/* Crud */ public Comment Save(Comment comment, bool updateTopicPostCount = true) { var newComment = comment.Id <= 0; var eventArgs = new CommentEventArgs() { Comment = comment }; if (newComment) { Creating.Raise(this, eventArgs); } else { Updating.Raise(this, eventArgs); } if (!eventArgs.Cancel) { //save comment _databaseContext.Database.Save(comment); //topic post count if (updateTopicPostCount) { UpdateTopicPostsCount(comment); } //parent comment state if (comment.ParentCommentId > 0) { var p = GetById(comment.ParentCommentId); if (p != null) { p.HasChildren = true; } Save(p, false); } if (newComment) { Created.Raise(this, eventArgs); } else { Updated.Raise(this, eventArgs); } } else { CancelledByEvent.Raise(this, eventArgs); } return(comment); }
public void Delete(Topic topic) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Deleting.RaiseAndContinue(this, eventArgs)) { _databaseContext.Database.Delete(topic); Deleted.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } }
public void Delete(Models.Forum forum) { var eventArgs = new ForumEventArgs() { Forum = forum }; if (Deleting.RaiseAndContinue(this, eventArgs)) { _databaseContext.Database.Delete(forum); Deleted.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } }
public void Delete(Comment comment) { var eventArgs = new CommentEventArgs() { Comment = comment }; if (Deleting.RaiseAndContinue(this, eventArgs)) { UpdateTopicPostsCount(comment, false); _databaseContext.Database.Delete(comment); Deleted.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } }
public void Lock(Topic topic) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Locking.RaiseAndContinue(this, eventArgs)) { topic.Locked = true; _databaseContext.Database.Save(topic); Locked.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } }
public void ChangeCategory(Topic topic, int newCategory) { var eventArgs = new TopicEventArgs() { Topic = topic }; if (Moving.RaiseAndContinue(this, eventArgs)) { topic.ParentId = newCategory; _databaseContext.Database.Save(topic); Moved.Raise(this, eventArgs); } else { CancelledByEvent.Raise(this, eventArgs); } }
/* CRUD */ public Topic Save(Topic topic) { var newTopic = topic.Id <= 0; var eventArgs = new TopicEventArgs() { Topic = topic }; if (newTopic) { Creating.Raise(this, eventArgs); } else { Updating.Raise(this, eventArgs); } if (!eventArgs.Cancel) { //save entity _databaseContext.Database.Save(topic); if (newTopic) { Created.Raise(this, eventArgs); } else { Updated.Raise(this, eventArgs); } } else { CancelledByEvent.Raise(this, eventArgs); } return(topic); }
public Models.Forum Save(Models.Forum forum) { var newForum = _databaseContext.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM forumForums WHERE id=@id", new { id = forum.Id }) == 0; var eventArgs = new ForumEventArgs() { Forum = forum }; if (newForum) { Creating.Raise(this, eventArgs); } else { Updating.Raise(this, eventArgs); } if (!eventArgs.Cancel) { if (newForum) { _databaseContext.Database.Insert(forum); Created.Raise(this, eventArgs); } else { _databaseContext.Database.Update(forum); Updated.Raise(this, eventArgs); } } else { CancelledByEvent.Raise(this, eventArgs); } return(forum); }