public ActionResult AddComment(string commentMessage, int postId) { // можливо краще використати авто-маппер var newComment = new CommentServiceReference.CommentDto(); newComment.Message = commentMessage; newComment.AuthorId = _authProvider.CurrentUserId; newComment.DatePosted = DateTime.Now; newComment.PostId = postId; _commentService.Add(newComment); var postCommentsViewModel = new PostCommentsViewModel(); postCommentsViewModel.PostComments = _commentService.GetByPostId(postId); postCommentsViewModel.PostId = postId; if (Request.IsAjaxRequest()) { return PartialView("PostCommentsPartial", postCommentsViewModel); } return View("PostCommentsPartial", postCommentsViewModel); }
public ActionResult GetPostComments(int postId) { var postCommentsViewModel = new PostCommentsViewModel(); postCommentsViewModel.PostComments = _commentService.GetByPostId(postId); postCommentsViewModel.PostId = postId; if (Request.IsAjaxRequest()) { return PartialView("PostCommentsPartial", postCommentsViewModel); } return View("PostCommentsPartial", postCommentsViewModel); }
public ActionResult RemoveComment(int commentId) { var comment = _commentService.GetById(commentId); int postId = comment.PostId; _commentService.RemoveById(commentId); var postCommentsViewModel = new PostCommentsViewModel(); postCommentsViewModel.PostComments = _commentService.GetByPostId(postId); postCommentsViewModel.PostId = postId; if (Request.IsAjaxRequest()) { return PartialView("PostCommentsPartial", postCommentsViewModel); } return View("PostCommentsPartial", postCommentsViewModel); }