Пример #1
0
        public ActionResult <PageData <User> > GetPaginated(int page, [FromQuery] PaginateQuery query)
        {
            PageData <User>     result    = new PageData <User> ();
            Func <User, object> orderFunc = a => a.Id;

            var list = userManager.Users.ToList();

            result.TotalPages = (int)Math.Ceiling(list.Count() / (double)query.PageSize);

            switch (query.SortBy)
            {
            case "email":
                orderFunc = a => a.Email;
                break;
            }

            if (!query.Desc)
            {
                result.List = list.OrderBy(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }
            else
            {
                result.List = list.OrderByDescending(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }

            return(result);
        }
        public async Task <PageData <BookingDTO> > GetPaginated(int page, [FromQuery] PaginateQuery query, [FromQuery] bool ByUser)
        {
            Func <BookingDTO, object> orderFunc = a => a.Id;
            PageData <BookingDTO>     result    = new PageData <BookingDTO> ();

            List <BookingDTO> bookingDTOList = new List <BookingDTO> ();
            var bookingList = await bookingRepository.GetAll();

            if (ByUser)
            {
                bookingList = bookingList.Where(e => e.UserId == Request.Cookies["User.ID"]);
            }

            foreach (var booking in bookingList)
            {
                var numberPlate = (await carRepository.GetById(booking.CarId)).NumberPlate;
                var userEmail   = (await userManager.FindByIdAsync(booking.UserId)).Email;

                var bookingDTO = mapper.Map <Booking, BookingDTO> (booking);
                bookingDTO.UserEmail   = userEmail;
                bookingDTO.NumberPlate = numberPlate;

                bookingDTOList.Add(bookingDTO);
            }

            result.TotalPages = (int)Math.Ceiling(bookingDTOList.Count() / (double)query.PageSize);

            switch (query.SortBy)
            {
            case "totalCost":
                orderFunc = a => a.TotalCost;
                break;

            case "date":
                orderFunc = a => a.PickUpDate;
                break;
            }

            if (!query.Desc)
            {
                result.List = bookingDTOList.OrderBy(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }
            else
            {
                result.List = bookingDTOList.OrderByDescending(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }

            return(result);
        }
Пример #3
0
        public PaginatedList <TEntity> Handle(PaginateQuery <TEntity> args)
        {
            using (var dbContextScope = _dbContextScopeFactory.CreateReadOnly())
            {
                IDbContext dbCtx = dbContextScope.DbContexts.GetByInterface <TDbContext>();

                ((DbContext)dbCtx).Configuration.ProxyCreationEnabled = false;

                IQueryable <TEntity> entities = dbCtx.Set <TEntity>();

                entities = entities.Include(args);
                entities = entities.Where(args);
                entities = entities.OrderBy(args);
                var total = entities.Count();
                entities = entities.Paginate(args);

                return(new PaginatedList <TEntity>(entities.ToList(), args.PageIndex, args.PageSize, total));
            }
        }
Пример #4
0
        public async Task <PageData <CarType> > GetPaginated(int page, [FromQuery] PaginateQuery query)
        {
            ISpecification <CarType> carTypeExpSpec =
                new ExpressionSpecification <CarType> (e => EF.Functions.Like(e.Name, $"%{query.Search.Trim()}%"));
            Func <CarType, object> orderFunc = a => a.Id;
            PageData <CarType>     result    = new PageData <CarType> ();

            var list = await carTypeRepository.Search(carTypeExpSpec);

            result.TotalPages = (int)Math.Ceiling(list.Count() / (double)query.PageSize);

            switch (query.SortBy)
            {
            case "name":
                orderFunc = a => a.Name;
                break;

            case "seat":
                orderFunc = a => a.Seat;
                break;

            case "cost":
                orderFunc = a => a.Cost;
                break;
            }

            if (!query.Desc)
            {
                result.List = list.OrderBy(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }
            else
            {
                result.List = list.OrderByDescending(orderFunc).Skip((page - 1) * query.PageSize).Take(query.PageSize);
            }

            return(result);
        }