public async Task <IActionResult> GetOffers([FromQuery] OfferPaginationParams offerPaginationParams)
        {
            var offers = await database.SchoolRepository.GetPagedOffers(offerPaginationParams);

            var offersToReturn = mapper.Map <ICollection <OfferDetailsDto> >(offers);

            Response.AddPagination(offers.CurrentPage, offers.PageSize, offers.TotalCount, offers.TotalPages);

            return(Ok(offersToReturn));
        }
Example #2
0
        public async Task <PagedList <Offer> > GetPagedOffers(OfferPaginationParams offerPaginationParams)
        {
            var offers = await GetAll <Offer>();

            offers = offers.Where(o => !o.School.Owner.IsBlocked)
                     .OrderBy(o => o.Packages.OrderBy(p => p.PricePerOne).FirstOrDefault().PricePerOne /
                              o.Packages.OrderBy(p => p.PricePerOne).FirstOrDefault().Hours);

            if (!string.IsNullOrEmpty(offerPaginationParams.Name))
            {
                offers = offers.Where(o => o.Name.ToLower().Contains(offerPaginationParams.Name.ToLower()));
            }

            if (!string.IsNullOrEmpty(offerPaginationParams.State))
            {
                offers = offers.Where(o => o.School.State.ToLower().Contains(offerPaginationParams.State.ToLower()));
            }

            if (!string.IsNullOrEmpty(offerPaginationParams.City))
            {
                offers = offers.Where(o => o.School.City.ToLower().Contains(offerPaginationParams.City.ToLower()));
            }

            if (offerPaginationParams.IsRental)
            {
                offers = offers.Where(o => o.School.IsRental);
            }

            if (offerPaginationParams.GroupCount != null)
            {
                offers = offers.Where(o => (!o.IsMore && o.Count == offerPaginationParams.GroupCount) ||
                                      (o.IsMore && o.Count <= offerPaginationParams.GroupCount));
            }

            return(PagedList <Offer> .Create(offers.AsQueryable(), offerPaginationParams.PageNumber, offerPaginationParams.PageSize));
        }