Exemplo n.º 1
0
        public ActionResult DisplayPublishedPost(Guid postId)
        {
            var view = new PublishedPostWithCommentsView(MvcApplication.MongoDatabase);

            var publishedPostWithComments = view.Find(postId);

            var model = new DisplayPublishedPostViewModel
            {
                Post = publishedPostWithComments
            };

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult AddCommentToPublishedPost(Guid postId, DisplayPublishedPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                var postsRepository = new PostsRepository(MvcApplication.MongoDatabase);

                var post = postsRepository.Find(postId);

                post.AddComment(model.NewComment.Author, model.NewComment.Comment);

                postsRepository.Save(post);
            }

            return RedirectToRoute("Posts.DisplayPublishedPost", new { postId });
        }