/* 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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #4
0
 public void Update(SimModel simModel, SimState simState)
 {
     Updating.Raise(this, new GameStateUpdateEventArgs(simModel, simState));
     OnUpdate(simModel, simState);
     TryMove(simModel, simState, Location.Add(Velocity));
 }
 public void Update(GameState gameState, long elapsedMilliseconds)
 {
     Updating.Raise(this, new GameStateUpdateEventArgs(gameState, elapsedMilliseconds));
     OnUpdate(gameState, elapsedMilliseconds);
 }