Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Gordon Saxby 1404 posts 1745 karma points
    Apr 01, 2016 @ 09:18
    Gordon Saxby

    Using API - is this right

    Sorry, probable "stupid question" alert! Is the code below the correct approach if I want to add topics via code?

                var unitofWorkManager = new UnitOfWorkManager(ContextPerRequest.Db);
                Topic topic = null;
                using (var unitOfWork = unitofWorkManager.NewUnitOfWork())
                        var newTopic = new Topic
                                           Category = forumCategory, 
                                           Name = "Title", 
                                           MemberId = intMemberId
                        topic = Dialogue.Logic.Services.ServiceFactory.TopicService.Add(newTopic);
                        // Commit the transaction
                    catch (Exception ex)
                        // Roll back database changes 
                        // Log the error

    I have read this which is where the code sample comes from, but I just wanted to check I needed the "unitofwork" stuff.

Please Sign in or register to post replies

Write your reply to: