/// <summary> /// Create Pagination Information for Items /// </summary> /// <param name="request"></param> /// <param name="items"></param> /// <param name="paginationFilter"></param> /// <returns></returns> public static Pagination <T> Create([ActionResultObjectValue] IList <T> items, PaginationFilter paginationFilter, HttpContext request) { items ??= new List <T>(); var pagedItems = items.Skip((paginationFilter.Page - 1) * paginationFilter.Limit).Take(paginationFilter.Limit).ToList(); return(Build(pagedItems, items.Count, paginationFilter, request)); }
/// <summary> /// Create Pagination Information for Items /// [ Recommended ] /// </summary> /// <param name="request"></param> /// <param name="items"></param> /// <param name="paginationFilter"></param> /// <returns></returns> public static async Task <Pagination <T> > CreateAsync([ActionResultObjectValue] IQueryable <T> items, PaginationFilter paginationFilter, HttpContext request) { if (items is null) { return(Build(new List <T>(), 0, paginationFilter, request)); } var pagedItems = await items.Skip((paginationFilter.Page - 1) *paginationFilter.Limit).Take(paginationFilter.Limit).ToListAsync(); var totalItems = await items.CountAsync(); return(Build(pagedItems, totalItems, paginationFilter, request)); }