private string CreateLink(PagedType pagedType, PuCommodityCategoryParams PuCommodityCategoryParams) { switch (pagedType) { case PagedType.Previous: return(Url.Link(nameof(PuCommodityCategoryPaged), new { PageNum = PuCommodityCategoryParams.PageNum - 1, PageSize = PuCommodityCategoryParams.PageSize })); case PagedType.Next: return(Url.Link(nameof(PuCommodityCategoryPaged), new { PageNum = PuCommodityCategoryParams.PageNum + 1, PageSize = PuCommodityCategoryParams.PageSize })); } return(string.Empty); }
public async Task <ActionResult <ActionResult <IEnumerable <PuCommodityCategoryDto> > > > PuCommodityCategoryPaged( [FromQuery] PuCommodityCategoryParams PuCommodityCategoryParams) { var res = new MessageModel <IEnumerable <PuCommodityCategoryDto> >(); PagedList <PuCommodityCategory> list = await _puCommodityCategoryServices.PuCommodityCategoryPaged(PuCommodityCategoryParams); string previousLink = list.HasPrevious ? CreateLink(PagedType.Previous, PuCommodityCategoryParams) : null; string nextLink = list.HasNext ? CreateLink(PagedType.Next, PuCommodityCategoryParams) : null; var pagination = new { currentPage = list.PageNum, totalPage = list.TotalPage, totalCount = list.TotalCount, previousLink, nextLink }; HttpContext.Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pagination)); res.Data = _mapper.Map <IEnumerable <PuCommodityCategoryDto> >(list); return(Ok(res)); }
public async Task <PagedList <PuCommodityCategory> > PuCommodityCategoryPaged(PuCommodityCategoryParams PuCommodityCategoryParams) { IQueryable <PuCommodityCategory> PuCommodityCategoryinfo = _pucommoditycategoryrepository.GetEntitys(); if (!string.IsNullOrWhiteSpace(PuCommodityCategoryParams.Name)) { PuCommodityCategoryinfo = PuCommodityCategoryinfo.Where(a => a.Name.Contains(PuCommodityCategoryParams.Name)); } return(await PagedList <PuCommodityCategory> .CreatePagedList(PuCommodityCategoryinfo, PuCommodityCategoryParams.PageSize, PuCommodityCategoryParams.PageNum)); }