diff --git a/server/Booking.Infrastructure/Persistence/Repositories/AdvertRepository.cs b/server/Booking.Infrastructure/Persistence/Repositories/AdvertRepository.cs index b06e71e..e2c8dfe 100644 --- a/server/Booking.Infrastructure/Persistence/Repositories/AdvertRepository.cs +++ b/server/Booking.Infrastructure/Persistence/Repositories/AdvertRepository.cs @@ -63,13 +63,15 @@ public IEnumerable Search( (query == null || a.Name.ToUpper().Contains(query.ToUpper())) && (category == null || a.CategoryId == category) && - (startDate == null || endDate == null || a.Reservations.Any(r => r.StartDate <= endDate && r.EndDate >= startDate)) && + (startDate == null || endDate == null || !a.Reservations.Any(r => r.StartDate <= endDate && r.EndDate >= startDate)) && (minCost == null || minCost <= a.PricePerNight) && (maxCost == null || a.PricePerNight <= maxCost) && - (singleBeds == null || CheckNumberOfSignleBeds(a, (int)singleBeds)) && - (doubleBeds == null || CheckNumberOfDoubleBeds(a, (int)doubleBeds)) && + (singleBeds == null || singleBeds >= 8 || a.NumberOfSingleBeds == singleBeds) && + (singleBeds == null || singleBeds < 8 || a.NumberOfSingleBeds >= singleBeds) && + (doubleBeds == null || doubleBeds >= 8 || a.NumberOfSingleBeds == doubleBeds) && + (doubleBeds == null || doubleBeds < 8 || a.NumberOfSingleBeds >= doubleBeds) && (wifi == null || a.Wifi) && (petsAllowed == null || a.PetsAllowed) && @@ -80,28 +82,4 @@ public IEnumerable Search( (heating == null || a.Heating) ); } - - private bool CheckNumberOfSignleBeds(Advert advert, int numberOfSignleBeds) - { - if (numberOfSignleBeds < 8) - { - return advert.NumberOfSingleBeds == numberOfSignleBeds; - } - else - { - return advert.NumberOfSingleBeds >= numberOfSignleBeds; - } - } - - private bool CheckNumberOfDoubleBeds(Advert advert, int numberOfDoubleBeds) - { - if (numberOfDoubleBeds < 8) - { - return advert.NumberOfDoubleBeds == numberOfDoubleBeds; - } - else - { - return advert.NumberOfDoubleBeds >= numberOfDoubleBeds; - } - } } \ No newline at end of file