Пример #1
0
        public void Handle(CommentApproved @event)
        {
            var collection = CreateCollection();

            var postsRepository = new PostsRepository(_mongoDatabase);

            var post = postsRepository.Find(@event.AggregateRootId);

            var comment = post.Comments.First(x => x.Id == @event.CommentId);

            var find = Query.EQ("_id", @event.AggregateRootId);

            var update = Update.AddToSet("Comments", comment.ToBsonDocument());

            collection.Update(find, update);
        }
Пример #2
0
        public void Handle(PostPublished @event)
        {
            var collection = CreateCollection();

            var postsRepository = new PostsRepository(_mongoDatabase);

            var post = postsRepository.Find(@event.AggregateRootId);

            var publishedPost = new PublishedPost
            {
                Id          = post.Id,
                Content     = post.Content,
                PublishedOn = post.PublishedOn,
                Title       = post.Title
            };

            collection.Insert(publishedPost);
        }