public async Task <IActionResult> PageAsync([NotNull, FromQuery] CryspyPageContext context) => Ok(await ApplicationService.PageAsync(context));
public async Task <CrispyPageResponse <CrispyApplicationPageResponse> > PageAsync([NotNull] CryspyPageContext context) { var response = new CrispyPageResponse <CrispyApplicationPageResponse>() { PageIndex = context.PageIndex, PageSize = context.PageSize }; var total = await Query().CountAsync(); response.Total = total; if (total == 0) { return(response); } response.Data = await Query().Page(context) .OrderBy(x => x.DateTimeCreated) .Select(x => new CrispyApplicationPageResponse(x.Id, x.Name)) .ToListAsync() ?? new List <CrispyApplicationPageResponse>(); return(response); }
public static IQueryable <T> Page <T>(this IQueryable <T> query, CryspyPageContext context) where T : class, new() => query.Skip(context.PageIndex * context.PageSize).Take(context.PageSize);