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 1465 posts 1887 karma points
    Apr 01, 2016 @ 09:18
    Gordon Saxby
    0

    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())
                {
                    try
                    {
                        var newTopic = new Topic
                                       {
                                           Category = forumCategory, 
                                           Name = "Title", 
                                           MemberId = intMemberId
                                       };
                        topic = Dialogue.Logic.Services.ServiceFactory.TopicService.Add(newTopic);
    
                        // Commit the transaction
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        // Roll back database changes 
                        unitOfWork.Rollback();
                        // Log the error
                    }
                }
    

    I have read this https://github.com/YodasMyDad/Dialogue#servicefactory--unitofwork which is where the code sample comes from, but I just wanted to check I needed the "unitofwork" stuff.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies