예제 #1
0
        /* 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
        /* 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);
        }
예제 #3
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);
        }