public async Task <PagedList <AcUserInfo> > GetUserInfoPaged(AcUserInfoParams acuserinfoparams) { IQueryable <AcUserInfo> acUserInfos = _acuserinfoinforepository.GetEntitys(); if (!string.IsNullOrWhiteSpace(acuserinfoparams.Account)) { acUserInfos = acUserInfos.Where(a => a.Account.Contains(acuserinfoparams.Account)); } return(await PagedList <AcUserInfo> .CreatePagedList(acUserInfos, acuserinfoparams.PageSize, acuserinfoparams.PageNum)); }
private string CreateLink(PagedType pagedType, AcUserInfoParams userInfoParams) { switch (pagedType) { case PagedType.Previous: return(Url.Link(nameof(GetUserInfoPaged), new { PageNum = userInfoParams.PageNum - 1, PageSize = userInfoParams.PageSize })); case PagedType.Next: return(Url.Link(nameof(GetUserInfoPaged), new { PageNum = userInfoParams.PageNum + 1, PageSize = userInfoParams.PageSize })); } return(string.Empty); }
public async Task <ActionResult <ActionResult <IEnumerable <AcUserInfoDto> > > > GetUserInfoPaged( [FromQuery] AcUserInfoParams acUserInfoParams) { var res = new MessageModel <IEnumerable <AcUserInfoDto> >(); PagedList <AcUserInfo> list = await _acUserInfoServices.GetUserInfoPaged(acUserInfoParams); string previousLink = list.HasPrevious ? CreateLink(PagedType.Previous, acUserInfoParams) : null; string nextLink = list.HasNext ? CreateLink(PagedType.Next, acUserInfoParams) : 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 <AcUserInfoDto> >(list); return(Ok(res)); }