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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
 public static PagedList <T> ToPagedList <T>(this ICollection <T> source, int pageIndex, int itemsPerPage)
 => PagedList <T> .Build(source, pageIndex, itemsPerPage);