public async Task <PagedList <PuSupplier> > PuSupplierPaged(PuSupplierParams puSupplierParams) { IQueryable <PuSupplier> pusupplierinfo = _pusupplierrepository.GetEntitys(); if (!string.IsNullOrWhiteSpace(puSupplierParams.Address)) { pusupplierinfo = pusupplierinfo.Where(a => a.Address.Contains(puSupplierParams.Address)); } return(await PagedList <PuSupplier> .CreatePagedList(pusupplierinfo, puSupplierParams.PageSize, puSupplierParams.PageNum)); }
private string CreateLink(PagedType pagedType, PuSupplierParams puSupplierParams) { switch (pagedType) { case PagedType.Previous: return(Url.Link(nameof(PuSupplierPaged), new { PageNum = puSupplierParams.PageNum - 1, PageSize = puSupplierParams.PageSize })); case PagedType.Next: return(Url.Link(nameof(PuSupplierPaged), new { PageNum = puSupplierParams.PageNum + 1, PageSize = puSupplierParams.PageSize })); } return(string.Empty); }
public async Task <ActionResult <ActionResult <IEnumerable <PuSupplierDto> > > > PuSupplierPaged( [FromQuery] PuSupplierParams puSupplierParams) { var res = new MessageModel <IEnumerable <PuSupplierDto> >(); PagedList <PuSupplier> list = await _pusupplierservices.PuSupplierPaged(puSupplierParams); string previousLink = list.HasPrevious ? CreateLink(PagedType.Previous, puSupplierParams) : null; string nextLink = list.HasNext ? CreateLink(PagedType.Next, puSupplierParams) : 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 <PuSupplierDto> >(list); return(Ok(res)); }