/* 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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        /* 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);
        }
示例#8
0
        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);
        }