public PagedViewModel(PageCounter counter, IQueryable <T> allItems) { Counter = counter ?? throw new ArgumentNullException(nameof(counter)); ItemsInThePage = null == allItems ? Array.Empty <T>().AsQueryable() : SlicePage(allItems, Counter); }
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); }
IQueryable <T> SlicePage(IQueryable <T> allItems, PageCounter page) => allItems.Skip((int)(page.Size * (page.Number - 1))).Take(page.Size);