public async Task <MessageModel <PageModel <TopicDetail> > > Get(int page = 1, string tname = "", string key = "") { var data = new MessageModel <PageModel <TopicDetail> >(); int intTotalCount = 6; int TotalCount = 0; int PageCount = 1; List <TopicDetail> topicDetails = new List <TopicDetail>(); //总数据,使用AOP切面缓存 //topicDetails = await _topicDetailServices.GetTopicDetails(); topicDetails = await _topicDetailServices.Query(a => !a.tdIsDelete && a.tdSectendDetail == "tbug"); if (!string.IsNullOrEmpty(key)) { topicDetails = topicDetails.Where(t => (t.tdName != null && t.tdName.Contains(key)) || (t.tdDetail != null && t.tdDetail.Contains(key))).ToList(); } tname = UnicodeHelper.UnicodeToString(tname); if (!string.IsNullOrEmpty(tname)) { var tid = (await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id.ObjToInt(); topicDetails = topicDetails.Where(t => t.TopicId == tid).ToList(); } //筛选后的数据总数 TotalCount = topicDetails.Count; //筛选后的总页数 PageCount = (Math.Ceiling(TotalCount.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt(); topicDetails = topicDetails.OrderByDescending(d => d.Id).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList(); return(new MessageModel <PageModel <TopicDetail> >() { msg = "获取成功", success = TotalCount >= 0, response = new PageModel <TopicDetail>() { page = page, pageCount = PageCount, dataCount = TotalCount, data = topicDetails, } }); }
public async Task <object> Get(int page = 1, string tname = "") { int intTotalCount = 6; int TotalCount = 1; List <TopicDetail> topicDetails = new List <TopicDetail>(); topicDetails = await _topicDetailServices.Query(a => !a.tdIsDelete && a.tdSectendDetail == "tbug"); if (!string.IsNullOrEmpty(tname)) { var tid = (await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id.ObjToInt(); topicDetails = topicDetails.Where(t => t.TopicId == tid).ToList(); } topicDetails = topicDetails.OrderByDescending(d => d.Id).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList(); return(Ok(new { success = true, page = page, pageCount = TotalCount, Article = topicDetails })); }
public async Task <MessageModel <PageModel <TopicDetail> > > Get(int page = 1, string tname = "") { var data = new MessageModel <PageModel <TopicDetail> >(); int intTotalCount = 6; int TotalCount = 0; int PageCount = 1; List <TopicDetail> topicDetails = new List <TopicDetail>(); topicDetails = await _topicDetailServices.Query(a => !a.tdIsDelete && a.tdSectendDetail == "tbug"); if (!string.IsNullOrEmpty(tname)) { var tid = (await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id.ObjToInt(); topicDetails = topicDetails.Where(t => t.TopicId == tid).ToList(); } //数据总数 TotalCount = topicDetails.Count; //总页数 PageCount = (Math.Ceiling(topicDetails.Count.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt(); topicDetails = topicDetails.OrderByDescending(d => d.Id).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList(); return(new MessageModel <PageModel <TopicDetail> >() { Msg = "获取成功", Success = topicDetails.Count >= 0, Response = new PageModel <TopicDetail>() { page = page, pageCount = PageCount, dataCount = TotalCount, data = topicDetails, } }); }