public Task <PagedList <TEntity> > GetAllAsync(
     IPagingParams pagingParams,
     params Expression <Func <TEntity, object> >[] includeProperties
     )
 {
     return(GetWhere(null, includeProperties).ToPagedListAsync(pagingParams));
 }
 public PagedList(IPagingParams collectionParams, int count)
 {
     CurrentPage = collectionParams.PageNumber;
     PageSize    = collectionParams.PageSize;
     TotalCount  = count;
     TotalPages  = (int)Math.Ceiling(count / (double)collectionParams.PageSize);
 }
        public static async Task <PagedList <TEntity> > ToPagedListAsync <TEntity>(
            this IQueryable <TEntity> source,
            IPagingParams pagingParams
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (pagingParams == null)
            {
                throw new ArgumentNullException(nameof(pagingParams));
            }

            if (pagingParams.PageNumber < 0 || pagingParams.PageSize < 0)
            {
                throw new ArgumentException("Page number or page size cannot be less than zero!");
            }

            PagedList <TEntity> pagedList = new PagedList <TEntity>(pagingParams, await source.CountAsync());
            var items = await source.Skip((pagingParams.PageNumber - 1) *pagingParams.PageSize)
                        .Take(pagingParams.PageSize)
                        .ToListAsync();

            pagedList.AddRange(items);
            return(pagedList);
        }
        public async Task <PagedList <EmployeeDto> > GetPagedEmployee(IPagingParams pagingParams)
        {
            var entity = await _repository.GetPagedEmployee(pagingParams);

            return(new PagedList <EmployeeDto>(
                       entity.PageItems.Select(_ => _mapper.Map <EmployeeDto>(_)).ToList(),
                       entity.TotalItems,
                       pagingParams
                       ));
        }
        public static IQueryable <T> ApplyPaging <T>(this IQueryable <T> items, IPagingParams pagingParams)
        {
            if (pagingParams?.PageSize != null && pagingParams.PageNumber.HasValue)
            {
                return(items.Skip(pagingParams.PageSize.Value * (pagingParams.PageNumber.Value - 1))
                       .Take(pagingParams.PageSize.Value));
            }

            return(items);
        }
Exemplo n.º 6
0
 private PagedList(IQueryable <T> source, IPagingParams page)
 {
     TotalItems = source.Count();
     if (page != null)
     {
         PageNumber = page.PageNumber.GetValueOrDefault();
         PageSize   = page.PageSize.GetValueOrDefault();
     }
     PageItems = source
                 .ApplyPaging(page)
                 .ToList();
 }
Exemplo n.º 7
0
        public PagedList(List <T> pageItems, int totalItems, IPagingParams page)
        {
            TotalItems = totalItems;
            PageItems  = pageItems;

            if (page == null)
            {
                return;
            }
            PageNumber = page.PageNumber.GetValueOrDefault();
            PageSize   = page.PageSize.GetValueOrDefault();
        }
Exemplo n.º 8
0
        public async Task <IPagedList <IVehicleMake> > GetAllAsync(
            IFilteringParams filteringParams,
            IPagingParams pagingParams,
            ISortingParams sortingParams)
        {
            IQueryable <VehicleMake> makeList = await _repository.GetAllAsync <VehicleMake>();

            // Filtering
            if (!String.IsNullOrEmpty(filteringParams.SearchString))
            {
                makeList = makeList.Where(x => x.Name.ToLower().Contains(filteringParams.SearchString.ToLower()));
            }

            // Sorting
            switch (sortingParams.Sorting)
            {
            case "name_desc":
                makeList = makeList.OrderByDescending(x => x.Name);
                break;

            case "id":
                makeList = makeList.OrderBy(x => x.Id);
                break;

            case "id_desc":
                makeList = makeList.OrderByDescending(x => x.Id);
                break;

            case "abrv":
                makeList = makeList.OrderBy(x => x.Abrv);
                break;

            case "abrv_desc":
                makeList = makeList.OrderByDescending(x => x.Abrv);
                break;

            default:
                makeList = makeList.OrderBy(x => x.Name);
                break;
            }
            var pagedList = makeList.ToPagedList(pagingParams.PageNumber, pagingParams.PageSize);

            if (pagedList.PageCount < pagedList.PageNumber)
            {
                makeList.ToPagedList(1, pagingParams.PageSize);
            }
            return(pagedList);
        }
        public async Task<PagedList<Employee>> GetPagedEmployee(IPagingParams pagingParams)
        {
            var query = await _dbSet.AsNoTracking()
                .Select(e => new Employee
                {
                    Id = e.Id,
                    Name = e.Name,
                    LastName = e.LastName,
                    Email = e.Email,
                    BirthDate = e.BirthDate,
                    Gender = e.Gender,
                    IsActive = e.IsActive,
                    EmployeeSkills = e.EmployeeSkills.Select(s => new EmployeeSkill { Skill = s.Skill }).ToList()
                }).ToPagedListAsync(pagingParams);

            return query;
        }
 public static PagedList <T> ToPagedList <T>(this IQueryable <T> items, IPagingParams pagingParams)
 {
     return(PagedList <T> .GetPagedList(items, pagingParams));
 }
Exemplo n.º 11
0
 public PagingFactory(IPagingParams pagingParams)
 {
     _pagingParams = pagingParams ?? throw new ArgumentNullException(nameof(IPagingParams));
 }
Exemplo n.º 12
0
 public async Task <IPagedList <IVehicleMake> > FindMakeAsync(IFilteringParams filter, ISortingParams sorter, IPagingParams pager)
 {
     return(await unitOfWork.Makers.FindMakeAsync(filter, sorter, pager));
 }
Exemplo n.º 13
0
        public static async Task <PagedList <T> > GetPagedListAsync(IQueryable <T> source, IPagingParams page)
        {
            var paged = new PagedList <T>
            {
                TotalItems = source.Count(),
                PageNumber = page.PageNumber.GetValueOrDefault(),
                PageSize   = page.PageSize.GetValueOrDefault(),
                PageItems  = await source
                             .ApplyPaging(page)
                             .ToListAsync()
            };

            return(paged);
        }
Exemplo n.º 14
0
 public static PagedList <T> GetPagedList(IQueryable <T> source, IPagingParams page)
 {
     return(new PagedList <T>(source, page));
 }
Exemplo n.º 15
0
        public async Task <IPagedList <IVehicleMake> > FindMakeAsync(IFilteringParams filter, ISortingParams sorter, IPagingParams pager)
        {
            var makers = await context.Makers
                         .Where(m => string.IsNullOrEmpty(filter.Search)?m != null : m.Name.ToLower().Contains(filter.Search.ToLower()))
                         .OrderByDescending(x => sorter.SortDirection == "dsc" ? x.Name : "")
                         .OrderBy(x => string.IsNullOrEmpty(sorter.SortDirection) || sorter.SortDirection == "asc" ? x.Name : "")
                         .ToListAsync();


            return(await mapper.Map <IEnumerable <IVehicleMake> >(makers).ToPagedListAsync(pager.CurrentPage, pager.PageSize));
        }
Exemplo n.º 16
0
        public static async Task <TableResponseCommon <T> > ToTableResponseAsync <T>(this IQueryable <T> query, IPagingParams searchModel)
        {
            int itemsCount;
            var items = await query.Paging(searchModel.PagingParams, out itemsCount).ToArrayAsync();

            return(new TableResponseCommon <T>
            {
                Items = items,
                ItemsCount = itemsCount
            });
        }
 public static async Task <PagedList <T> > ToPagedListAsync <T>(this IQueryable <T> items, IPagingParams pagingParams)
 {
     return(await PagedList <T> .GetPagedListAsync(items, pagingParams));
 }