/// <summary> /// Convert list to paged list according to paging request /// </summary> /// <typeparam name="T">Object type</typeparam> /// <param name="list">List of objects</param> /// <param name="pagingRequestModel">Paging request model</param> /// <returns>Paged list</returns> public static IPagedList <T> ToPagedList <T>(this IList <T> list, IPagingRequestModel pagingRequestModel) { return(new PagedList <T>(list, pagingRequestModel.Page - 1, pagingRequestModel.PageSize)); }
private static void ApplyPaging(IPagingRequestModel model, IQueryPaging query) { int page = model.Page ?? 1; int pagesize = model.PageSize ?? 100; query.Skip = pagesize * (page - 1); query.Take = pagesize; }
// In-memory paging of objects public static IEnumerable <T> PaginationByRequestModel <T>(this IEnumerable <T> collection, IPagingRequestModel requestModel) { return(collection.Skip((requestModel.Page - 1) * requestModel.PageSize).Take(requestModel.PageSize)); }
/// <summary> /// Convert async-enumerable sequence to paged list according to paging request /// </summary> /// <typeparam name="T">Object type</typeparam> /// <param name="collection">Async-enumerable sequence of objects</param> /// <param name="pagingRequestModel">Paging request model</param> /// <returns>Paged list</returns> public static async Task <IPagedList <T> > ToPagedListAsync <T>(this IAsyncEnumerable <T> collection, IPagingRequestModel pagingRequestModel) { var list = await collection.ToListAsync(); return(list.ToPagedList(pagingRequestModel)); }