public FetchPagingParameters(FetchParameters <TModel> model) : base(model)
 {
     PagingRule = new PagingRule()
     {
         PageIndex = 1, PageSize = int.MaxValue
     };
 }
 public FetchParameters <TModel> SetPaging(int pageIndex, int pageSize)
 {
     PagingRule = new PagingRule()
     {
         PageIndex = pageIndex, PageSize = pageSize
     };
     return(this);
 }
        internal PagingResult <TModel> Paging <TModel>(IQueryable <TModel> items, PagingRule paging) where TModel : class
        {
            var total  = 0;
            var result = FormPagingQuery(items, paging, out total).ToList();
            var res    = new PagingResult <TModel>()
            {
                Items           = result,
                PageIndex       = paging.PageIndex,
                PageSize        = paging.PageSize,
                TotalItemsCount = total
            };

            if (res.Items == null)
            {
                // just in case
                res.Items = new List <TModel>();
            }
            return(res);
        }
 public IPagingFetchBuilder <TModel> SetPaging(PagingRule pagingRule)
 {
     fetchParameters.SetPaging(pagingRule.PageIndex, pagingRule.PageSize);
     return(this);
 }
        // TODO: doublecheck deadlocks
        internal async Task <PagingResult <TModel> > PagingAsync <TModel>(IQueryable <TModel> items, PagingRule paging) where TModel : class
        {
            var total  = 0;
            var result = await FormPagingQuery(items, paging, out total).ToListAsync().ConfigureAwait(false);

            var res = new PagingResult <TModel>()
            {
                Items           = result,
                PageIndex       = paging.PageIndex,
                PageSize        = paging.PageSize,
                TotalItemsCount = total
            };

            if (res.Items == null)
            {
                // just in case
                res.Items = new List <TModel>();
            }
            return(res);
        }
        private IQueryable <TModel> FormPagingQuery <TModel>(IQueryable <TModel> items, PagingRule paging, out int total)
            where TModel : class
        {
            Check.NotNull(items, "items");

            total = items.Count();

            // unload everything if paging not defined.
            paging.PageSize = paging.PageSize <= 0 ?
                              total
                                : paging.PageSize;

            if ((paging.PageIndex - 1) * paging.PageSize >= total)
            {
                paging.PageSize  = paging.PageSize == 0 ? int.MaxValue : paging.PageSize;
                paging.PageIndex = (total / paging.PageSize) - 1;
            }

            if (paging.PageIndex <= 0)
            {
                paging.PageIndex = 1;
            }

            var result = items
                         .Skip(paging.PageSize * (paging.PageIndex - 1))
                         .Take(paging.PageSize);

            return(result);
        }
 public Task <PagingResult <TModel> > PagingAsync(IQueryable <TModel> items, PagingRule paging)
 {
     return(repository.PagingAsync(items, paging));
 }