public async Task <PagedList <PrProductTask> > GetPrProductTaskPaged(PrProductTaskParams prProductTaskParams) { IQueryable <PrProductTask> prProductTask = _iprproducttaskrepository.GetEntitys(); if (!string.IsNullOrWhiteSpace(prProductTaskParams.SearchInfo)) { prProductTask = prProductTask.Where(a => a.ProductNavigation.Name.Contains(prProductTaskParams.SearchInfo) || a.No.Contains(prProductTaskParams.SearchInfo) || a.Batch.Contains(prProductTaskParams.SearchInfo)); } return(await PagedList <PrProductTask> .CreatePagedList(prProductTask, prProductTaskParams.PageSize, prProductTaskParams.PageNum)); }
private string CreateLink(PagedType pagedType, PrProductTaskParams prProductTaskParams) { switch (pagedType) { case PagedType.Previous: return(Url.Link(nameof(GetPrProductTasks), new { PageNum = prProductTaskParams.PageNum - 1, PageSize = prProductTaskParams.PageSize })); case PagedType.Next: return(Url.Link(nameof(GetPrProductTasks), new { PageNum = prProductTaskParams.PageNum + 1, PageSize = prProductTaskParams.PageSize })); } return(string.Empty); }
public async Task <ActionResult <IEnumerable <PrProductTaskDto> > > GetPrProductTasks([FromQuery] PrProductTaskParams prProductTaskParams) { var res = new MessageModel <IEnumerable <PrProductTaskDto> >(); var list = await _prProductTaskServices.GetPrProductTaskPaged(prProductTaskParams); string previousLink = list.HasPrevious ? CreateLink(PagedType.Previous, prProductTaskParams) : null; string nextLink = list.HasNext ? CreateLink(PagedType.Next, prProductTaskParams) : 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 <PrProductTaskDto> >(list); return(Ok(res)); }