Пример #1
0
        public PagedViewModel(PageCounter counter, IQueryable <T> allItems)
        {
            Counter = counter ?? throw new ArgumentNullException(nameof(counter));

            ItemsInThePage = null == allItems
                           ? Array.Empty <T>().AsQueryable()
                           : SlicePage(allItems, Counter);
        }
Пример #2
0
        public PagedViewModel <T> Paginate <T>(IQueryable <T> allItems, PageRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var counter = new PageCounter((uint)request.PageNumber
                                          , (byte)request.PageSize
                                          , (uint)(allItems?.Count() ?? 0));

            var vm = new PagedViewModel <T>(counter, allItems);

            return(vm);
        }
Пример #3
0
 IQueryable <T> SlicePage(IQueryable <T> allItems, PageCounter page)
 => allItems.Skip((int)(page.Size * (page.Number - 1))).Take(page.Size);