public async Task <IEnumerable <RentalDTO> > Handle(RentalByFiltersQuery request, CancellationToken cancellationToken) { var query = new QueryRepository <Rental>(); if (request.CustomerId.HasValue) { query.AddSpecification(RentalRepositoryHelper.Specifications.ByCustomerId(request.CustomerId.Value)); } if (request.CarId.HasValue) { if (query.HasSpecifications) { query.AddSpecification(SpecificationType.And, RentalRepositoryHelper.Specifications.ByCustomerId(request.CustomerId.Value)); } else { query.AddSpecification(RentalRepositoryHelper.Specifications.ByCustomerId(request.CustomerId.Value)); } } query.AddInclusion(RentalRepositoryHelper.Inclusions.Cars()); query.AddInclusion(RentalRepositoryHelper.Inclusions.Customers()); IEnumerable <Rental> rentals = await _rentalRepository.GetAllAsync(query); return(_mapper.Map <IEnumerable <RentalDTO> >(rentals)); }