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));
            }
            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));
            }
 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));
 private Specification <Dealer> GetDealerSpecification(CarAdsQuery request, int?dealerId)
 => new DealerByIdSpecification(dealerId)
 .And(new DealerByNameSpecification(request.Dealer));