public IActionResult Index(int?page) { var list = GetExampleList(); var pagedList1 = PagedList <string> .Build(list, page ?? 1, 10); var pagedList2 = list.ToPagedList <string>(page ?? 1, 10); return(View(pagedList2)); }
public async Task <PagedList <TEntity> > GetManyFilteredAndPaged(Expression <Func <TEntity, bool> > predicate, PageParam pageParam) { var toSkip = (pageParam.PageNumber - 1) * pageParam.ItemsPerPage; var query = Collection.Find(predicate); var totalTask = query.CountDocumentsAsync(); var itemsTask = query.Skip(toSkip).Limit(pageParam.ItemsPerPage).ToListAsync(); await Task.WhenAll(totalTask, itemsTask); return(PagedList <TEntity> .Build(itemsTask.Result, totalTask.Result, pageParam.ItemsPerPage, pageParam.PageNumber)); }
public async Task <PagedList <TEntity> > GetPaged(PageParam pageParam) { var toSkip = (pageParam.PageNumber - 1) * pageParam.ItemsPerPage; var query = Collection.Find(_ => true); var totalTask = query.CountDocumentsAsync(); var itemsTask = query.Skip(toSkip).Limit(pageParam.ItemsPerPage).ToListAsync(); await Task.WhenAll(totalTask, itemsTask); return(PagedList <TEntity> .Build(itemsTask.Result, totalTask.Result, pageParam.ItemsPerPage, pageParam.PageNumber)); }
public static PagedList <T> ToPagedList <T>(this ICollection <T> source, int pageIndex, int itemsPerPage) => PagedList <T> .Build(source, pageIndex, itemsPerPage);