public ActionResult TopicDetails(int?id, int page = 1) { if (id == null) { return(HttpNotFound()); } // Comment comment = db.Comments.FirstOrDefault(t => t.TopicId == id); Topic topic = db.Topics.FirstOrDefault(t => t.Id == id); ViewBag.TopicId = topic.Id; ViewBag.TopicTitle = topic.Title; ViewBag.TopicDescription = topic.Description; var comments = db.Comments.Where(t => t.TopicId == id); if (comments == null) { return(HttpNotFound()); } int pageSize = 5; // количество объектов на страницу IEnumerable <Comment> commentsPerPages = comments.OrderBy(p => p.TopicId == id).Skip((page - 1) * pageSize).Take(pageSize); PageInfo pageInfo = new PageInfo { PageNumber = page, PageSize = pageSize, TotalItems = comments.Count() }; PageCommentViewModel cvm = new PageCommentViewModel { PageInfo = pageInfo, Comments = commentsPerPages }; return(View(cvm)); // return View(topic); }
public async Task <PageCommentViewModel> getCommentByArticle(int aid, int pageSize, int page) { var pcv = new PageCommentViewModel(); //var titleid = await ArticleService.GetAsync(aid);//有问题有冲突,改为同一地方获取 //pcv.Title = titleid.Title; var fa = FindAll(n => n.ArticleID == aid).OrderByDescending(o => o.RegDate); var c = await Count(fa); pcv.Count = c; pcv.TotalItems = c; pcv.CurrentPage = page; pcv.ItemPerPage = pageSize; if (c != 0) { var fbp = FindByPageAsync(fa, pageSize, page, s => new CommentViewModel { IP = s.IP, Advice = s.Advice, RegDate = s.RegDate }); pcv.Entity = await fbp; } return(pcv); }