[HttpGet]//根据用户id得到全部主题(有效) public async Task <Result> getDiscussByUserId(int pageIndex) { //var myPlate = await _plateBll.GetEntities(u => == plateId).Include(u => u.discusses).ThenInclude(u => u.user).FirstOrDefaultAsync(); var myDiscuss = await _discussBll.GetEntities(u => u.user.id == _user.id && u.is_delete == delFlagNormal).Include(u => u.user).Include(u => u.plate).ToListAsync(); //数据筛选 var dataFilter = (from r in myDiscuss select new { r.id, r.introduction, r.time, r.title, r.type, plate = new { r.plate?.id }, user = new { r.user?.username, r.user?.icon } }).ToList(); //现在升级一下,开始分页 int pageSize = 10;//每页数量从redis中获取 //LinqHelper.GetPageEntities(dataFilter, pageSize, out int total); int total = dataFilter.Count(); var pageData = dataFilter .OrderByDescending(u => u.id) //降序排序 .Skip(pageSize * (pageIndex - 1)) .Take(pageSize).AsQueryable(); return(Result.Success().SetData(new { pageData, pageSize, total })); }
public async Task <Result> getCommentsByDiscussId(int discussId, int pageIndex) { if (discussId == 0) { return(Result.Error()); } var discussData = await _discussBll.GetEntities(u => u.id == discussId).Include(u => u.comments).ThenInclude(u => u.user).FirstOrDefaultAsync(); var commentList = from r in discussData.comments where r.is_delete == delFlagNormal select r; var dataFilter = from r in commentList select new { r.id, r.time, r.content, user = new { r.user?.username, r.user?.id, r.user?.icon } }; //现在升级一下,开始分页 int pageSize = 10;//每页数量从redis中获取 int total = dataFilter.Count(); var pageData = dataFilter .OrderByDescending(u => u.id) //降序排序 .Skip(pageSize * (pageIndex - 1)) .Take(pageSize).AsQueryable(); return(Result.Success().SetData(new { pageData, pageSize, total })); }