public ActionResult GetComments(string name, int page = 0) { var comments = this.commentsService.GetCommentsByLakeName(name, page * Constants.ShowedComments, Constants.ShowedComments).ToList(); var commentsCount = this.commentsService.GetCommentsCount(name); var hasPrev = page > 0; var hasNext = comments.Count() == Constants.ShowedComments && commentsCount > page * Constants.ShowedComments + Constants.ShowedComments; var model = new GetCommentsViewModel(); model.Comments = comments; model.LakeName = name; if (hasPrev) { model.HasPrev = hasPrev; model.PrevPage = page - 1; } if (hasNext) { model.HasNext = hasNext; model.NextPage = page + 1; } foreach (var comment in model.Comments) { comment.Comments = comment.Comments.OrderBy(i => i.PostedDate).ToList(); } return(PartialView("_CommentsPartial", model)); }
public async Task <IActionResult> GetComments([FromBody] GetCommentsViewModel commentsVm) { if (!ModelState.IsValid) { return(new BadResponseResult(ModelState)); } Logger.LogInformation($"{nameof(CommentsController)}.{nameof(GetComments)}.Start"); var comments = await MainDb.Comments.GetComments(commentsVm.UserId, commentsVm.QuestionId, commentsVm.PageParams.Offset, commentsVm.PageParams.Count); await Hub.Monitoring.UpdateUrlMonitoring(commentsVm.UserId, UrlMonitoringType.GetsComments); Logger.LogInformation($"{nameof(CommentsController)}.{nameof(GetComments)}.End"); return(new OkResponseResult(comments.Select(x => new CommentViewModel { CommentId = x.CommentId, DislikesCount = x.DislikesCount, LikesCount = x.LikesCount, Login = x.FirstName + " " + x.LastName, PreviousCommentId = x.PreviousCommentId, Text = x.Text, UserId = x.UserId, YourFeedbackType = x.YourFeedbackType, CommentedDate = x.CommentedDate, SmallAvatarUrl = MediaConverter.ToFullAvatarUrl(x.OriginalAvatarUrl, AvatarSizeType.Small) }).ToList())); }
public async Task <AllCommentsViewModel> GetComments([FromQuery] GetCommentsViewModel viewModel) { var user = this.User.FindFirst(ClaimTypes.NameIdentifier); string userId = null; if (user != null) { userId = user.Value; } var comments = new AllCommentsViewModel() { Page = viewModel.Page, CommentCount = this.commentService.GetCommentsCountForItem(viewModel.ItemId), CommentPerPage = CommentsPerPage, Comments = await this.commentService.GetCommentsForItemAsync(CommentsPerPage, viewModel.Page, viewModel.ItemId, userId), }; return(comments); }