public ActionResult GetSelectedPageComments(int id, int pageNumber) { var facilityComments = this.facilities.GetLatestFacilityComments(id); List <CommentViewModel> commentsViewModel = AutoMapperConfig.Configuration.CreateMapper().Map <List <CommentViewModel> >(facilityComments); CommentsListViewModel commentsListViewModel = new CommentsListViewModel(); decimal totalCommentsCount = (decimal)commentsViewModel.Count(); commentsListViewModel.TotalPages = (int)Math.Ceiling((totalCommentsCount / (decimal)SportsBook.Data.Common.Constants.Constants.COUNT_OF_COMMENTS_PER_PAGE)); commentsListViewModel.CurrentPage = pageNumber; commentsListViewModel.Comments = commentsViewModel.Skip((int)(pageNumber - 1) * 5).Take(5).ToList(); return(this.PartialView("_PageableCommentsPartial", commentsListViewModel)); }
public List <CommentsListViewModel> GetAllCommentsByProduct(int productId) { List <CommentsListViewModel> commentsList = new List <CommentsListViewModel>(); _unitOfWork.Repository <ProductComments>().GetIncludeList(x => x.ProductId == productId, p => p.Product).OrderByDescending(x => x.AddedDate).ToList().ForEach(x => { CommentsListViewModel comments = new CommentsListViewModel { ProductId = x.ProductId, Comment = x.Comment, ProductName = x.Product.Name, UserId = x.UserId }; DateTime date = x.AddedDate; comments.AddedDate = TimeAgoCustom.TimeAgo(date); ApplicationUsers user = _userManager.FindByIdAsync(x.UserId).Result; comments.UserName = user.Name; commentsList.Add(comments); }); return(commentsList); }