public async Task <PaginableList <User> > GetPagedList(PageParameters <User> pageParameter) { PaginableList <User> dataSource = new PaginableList <User>(); IQueryable <User> query = _context.Users; if (pageParameter.Filter != null) { query = query.Where(pageParameter.Filter); } if (pageParameter.Includes != null) { pageParameter.Includes.ForEach(fk => query = query.Include(fk)); } dataSource.TotalRows = await query.CountAsync(); if (pageParameter.Sort != null) { query = pageParameter.Direction == GridDirection.Asc ? query.OrderBy(pageParameter.Sort) : query.OrderByDescending(pageParameter.Sort); } dataSource.Rows = await query .Skip((pageParameter.PageNumber - 1) *pageParameter.PageSize) .Take(pageParameter.PageSize) .ToListAsync(); return(dataSource); }
private PaginableList <UserIndexDto> MapEntityToIndex(PaginableList <User> users) { PaginableList <UserIndexDto> dto = new PaginableList <UserIndexDto>(); dto.Rows = _mapper.Map <IEnumerable <User>, List <UserIndexDto> >(users.Rows); dto.TotalRows = users.TotalRows; return(dto); }
public async Task <ActionResult <PaginableList <ProductIndexDto> > > GetAllPagedSP() { var procedureName = "IndexPaged" + typeof(Product).Name; var rows = await _service.GetList <ProductIndexDto>(procedureName, ParseIndexQueryString(Request.Query)); PaginableList <ProductIndexDto> paginableList = new PaginableList <ProductIndexDto>(); paginableList.Rows = rows.ToList(); paginableList.TotalRows = rows.Any() ? rows.FirstOrDefault().TotalRows : 0; return(paginableList); }
public async Task <ActionResult <PaginableList <UserIndexDto> > > GetAllPaged(int?pageSize, int?pageNumber, string sort = null, string dir = null, string fullName = null, string email = null, string role = null) { PaginableList <User> users = await _service.GetAll(GetIndexParameters(pageSize, pageNumber, sort, dir, fullName, email, role)); return(MapEntityToIndex(users)); }