public async Task <ActionResult> PutLike(OpenPostViewModel model, int postId) { await _postService.PutLike(postId); Post post = _postService.GetPostById(postId); PostViewModel postModel = new PostViewModel() { Likes = post.Likes }; model.PostViewModel = postModel; return(PartialView("_LikeCountPartial", model)); }
public async Task <ActionResult> Open(int postId) { OpenPostViewModel model = new OpenPostViewModel(); model.CommentsViewModel = new List <CommentViewModel>(); Post post = _postService.GetPostById(postId); if (post == null) { ModelState.AddModelError("", "Пост не найден"); return(View("error")); } ApplicationUser user = await _userService.FindByIdAsync(post.UserId); PostViewModel postModel = new PostViewModel() { Title = post.Title, Description = post.Description, AddedOn = post.AddedOn, Author = user.Email, Likes = post.Likes }; IEnumerable <Comment> comments = _commentService.GetCommentsByPostId(postId); if (comments != null) { foreach (var item in comments) { CommentViewModel commentViewModel = new CommentViewModel { Author = AuthenticationManager.User.Identity.Name, Text = item.Text }; model.CommentsViewModel.Add(commentViewModel); } } model.PostId = postId; model.PostViewModel = postModel; return(View("Open", model)); }
public async Task <ActionResult> AddComment(OpenPostViewModel model, int postId) { if (ModelState.IsValid) { CommentDTO commentDTO = new CommentDTO { Text = model.CommentText, PostId = postId, UserId = AuthenticationManager.User.Claims.ElementAt(0).Value }; OperationDetails result = await _commentService.AddComment(commentDTO); if (result.Succedeed) { IEnumerable <Comment> comments = _commentService.GetCommentsByPostId(postId); if (comments != null) { model.CommentsViewModel = new List <CommentViewModel>(); foreach (var item in comments) { CommentViewModel commentViewModel = new CommentViewModel { Author = AuthenticationManager.User.Identity.Name, Text = item.Text }; model.CommentsViewModel.Add(commentViewModel); } } return(PartialView("_CommentsPartial", model)); } ModelState.AddModelError(result.Property, result.Message); return(PartialView("_CommentsPartial", model)); } return(PartialView("_CommentsPartial", model)); }