예제 #1
0
            protected async Task <int> GetTotalPages(
                CarAdsQuery request,
                bool onlyAvailable = true,
                int?dealerId       = default,
                CancellationToken cancellationToken = default)
            {
                var carAdSpecification = this.GetCarAdSpecification(request, onlyAvailable);

                var dealerSpecification = this.GetDealerSpecification(request, dealerId);

                var totalCarAds = await this.carAdRepository.Total(
                    carAdSpecification,
                    dealerSpecification,
                    cancellationToken);

                return((int)Math.Ceiling((double)totalCarAds / CarAdsPerPage));
            }
예제 #2
0
            protected async Task <IEnumerable <TOutputModel> > GetCarAdListings <TOutputModel>(
                CarAdsQuery request,
                bool onlyAvailable = true,
                int?dealerId       = default,
                CancellationToken cancellationToken = default)
            {
                var carAdSpecification = this.GetCarAdSpecification(request, onlyAvailable);

                var dealerSpecification = this.GetDealerSpecification(request, dealerId);

                var searchOrder = new CarAdsSortOrder(request.SortBy, request.Order);

                var skip = (request.Page - 1) * CarAdsPerPage;

                return(await this.carAdRepository.GetCarAdListings <TOutputModel>(
                           carAdSpecification,
                           dealerSpecification,
                           searchOrder,
                           skip,
                           take : CarAdsPerPage,
                           cancellationToken));
            }
예제 #3
0
 private Specification <CarAd> GetCarAdSpecification(CarAdsQuery request, bool onlyAvailable)
 => new CarAdByManufacturerSpecification(request.Manufacturer)
 .And(new CarAdByCategorySpecification(request.Category))
 .And(new CarAdByPricePerDaySpecification(request.MinPricePerDay, request.MaxPricePerDay))
 .And(new CadAdOnlyAvailableSpecification(onlyAvailable));
예제 #4
0
 private Specification <Dealer> GetDealerSpecification(CarAdsQuery request, int?dealerId)
 => new DealerByIdSpecification(dealerId)
 .And(new DealerByNameSpecification(request.Dealer));