Exemplo n.º 1
0
 protected void SetDefaultPageSize(IPagingFilterDto pagingFilterDto)
 {
     if (pagingFilterDto.PageSize <= 0)
     {
         pagingFilterDto.PageSize = (int)systemConfigService.GetValueNumber(ConstantConfig.SystemConfigName.PageDefaultNumber);
     }
 }
Exemplo n.º 2
0
        private static void InitPagedModel <TModel>(this IQueryable <TModel> query, IPagingFilterDto pagingFilterDto, PagingResultDto <TModel> pagingModel)
        {
            pagingModel.RowCount    = query.Count();
            pagingModel.PageSize    = pagingFilterDto.PageSize;
            pagingModel.CurrentPage = pagingFilterDto.PageNumber;

            var pageCount = (double)pagingModel.RowCount / pagingModel.PageSize;

            pagingModel.PageCount = (int)Math.Ceiling(pageCount);

            IQueryable <TModel> queryResultPage = query
                                                  .Skip((pagingFilterDto.PageNumber - 1) * pagingFilterDto.PageSize)
                                                  .Take(pagingFilterDto.PageSize);

            pagingModel.Items = queryResultPage.ToList();
        }
Exemplo n.º 3
0
        public static PagingResultDto <TModel> PagedQuery <TModel>(this IQueryable <TModel> query, IPagingFilterDto pagingFilterDto)
        {
            if (pagingFilterDto.PageNumber <= 0)
            {
                pagingFilterDto.PageNumber = 1;
            }
            var result = new PagingResultDto <TModel>();

            InitPagedModel(query, pagingFilterDto, result);
            return(result);
        }
Exemplo n.º 4
0
        public static PagingResultDto <TModel> PagedQuery <TModel>(this IQueryable <TModel> query, IPagingFilterDto pagingFilterDto)
        {
            if (pagingFilterDto.PageNumber <= 0)
            {
                pagingFilterDto.PageNumber = 1;
            }
            var result = new PagingResultDto <TModel>();

            result.RowCount    = query.Count();
            result.PageSize    = pagingFilterDto.PageSize;
            result.CurrentPage = pagingFilterDto.PageNumber;

            var pageCount = (double)result.RowCount / result.PageSize;

            result.PageCount = (int)Math.Ceiling(pageCount);

            IQueryable <TModel> queryResultPage = query
                                                  .Skip((pagingFilterDto.PageNumber - 1) * pagingFilterDto.PageSize)
                                                  .Take(pagingFilterDto.PageSize);

            result.Items = queryResultPage.ToList();

            return(result);
        }