OurUmbraco.NotificationsWeb.Services.NotificationService.SubscribeToForum C# (CSharp) Method

SubscribeToForum() public method

public SubscribeToForum ( int forumId, int memberId ) : void
forumId int
memberId int
return void
        public void SubscribeToForum(int forumId, int memberId)
        {
            var r = _databaseContext.Database.SingleOrDefault<ForumSubscriber>(
                "SELECT * FROM forumsubscribers WHERE forumId=@0 and memberId=@1",
                forumId,
                memberId);

            if (r == null)
            {
                var rec = new ForumSubscriber();
                rec.MemberId = memberId;
                rec.ForumId = forumId;

                _databaseContext.Database.Insert(rec);
            }
        }

Usage Example

Example #1
0
 void ForumService_Created(object sender, ForumEventArgs e)
 {
     var content = ApplicationContext.Current.Services.ContentService.GetById(e.Forum.ParentId);
     if (content.ContentType.Alias == "Project")
     {
         var owner = content.GetValue<int>("owner");
         //NotificationsWeb.BusinessLogic.Forum.Subscribe(e.Forum.Id, owner);
         var ns = new NotificationService(ApplicationContext.Current.DatabaseContext);
         ns.SubscribeToForum(e.Forum.Id, owner);
     }
 }