Esempio n. 1
0
        public ActionResult ShowPost(ShowPostViewModel vm)
        {
            if (ModelState.IsValid)
            {
                commentService.CreateComment(new Comment()
                {
                    CommentContent = vm.CommentViewModel.CommentContent,
                    Email = vm.CommentViewModel.Email,
                    PostId = vm.CommentViewModel.PostId,
                    Website = vm.CommentViewModel.Website,
                    Name = vm.CommentViewModel.Name,
                    IsModerated = false
                });
                commentService.SaveChanges();
                ViewBag.Message = "Your comment will show after the Moderating";
            }


            var post = postService.GetPostById(vm.CommentViewModel.PostId);
            vm.Post = post;
            vm.Post.Comments = null;
            vm.Post.Comments = post.Comments != null ?
                                 post.Comments.Where(a => a.IsModerated == true && a.IsValid == true).ToList() :
                                 new List<Comment>();
            vm.CommentViewModel = new CommentViewModel();
            return View(vm);
        }
Esempio n. 2
0
 public ActionResult ShowPost(int postId = 1)
 {
     ShowPostViewModel vm = new ShowPostViewModel();
     var post = postService.GetPostById(postId);
     vm.Post = post;
     vm.Post.Comments = null;
     vm.Post.Comments = post.Comments != null ? 
                        post.Comments.Where(a => a.IsModerated == true && a.IsValid == true).ToList() : 
                        new List<Comment>();
     vm.CommentViewModel.PostId = postId;
     vm.PublishedBy = post.User.UserName ?? string.Empty;
     return View(vm);
 }