public async Task <IEnumerable <Room> > GetRoomsAsync(RoomsResourceParameters roomsResourceParameters) { if (roomsResourceParameters == null) { throw new ArgumentNullException(nameof(roomsResourceParameters)); } if (roomsResourceParameters.HasBalcony == null && roomsResourceParameters.RoomType == null && roomsResourceParameters.VacancyInDays == null && roomsResourceParameters.PriceLessThan == null && roomsResourceParameters.NumberOfPerson == null && string.IsNullOrWhiteSpace(roomsResourceParameters.SearchQuery)) { return(await GetRoomsAsync()); } var collection = _context.Rooms as IQueryable <Room>; if (!(roomsResourceParameters.HasBalcony == null)) { collection = collection.Where(r => r.HasBalcony == roomsResourceParameters.HasBalcony); } if (!(roomsResourceParameters.RoomType == null)) { var roomType = roomsResourceParameters.RoomType; collection = collection.Where(r => r.Type == roomType); } if (!(roomsResourceParameters.PriceLessThan == null)) { collection = collection.Where(r => r.PriceForDay < roomsResourceParameters.PriceLessThan); } if (!(roomsResourceParameters.NumberOfPerson == null)) { collection = collection.Where(r => r.MaxNumberOfPerson == roomsResourceParameters.NumberOfPerson); } if (!(roomsResourceParameters.VacancyInDays == null)) { if (!_bookingsRepository.AreDatesCorrect(roomsResourceParameters.VacancyInDays)) { return(null); } var roomsIds = await GetVacancyRoomsAsync(roomsResourceParameters.VacancyInDays); collection = collection.Where(r => roomsIds.Contains(r.Id)); } if (!string.IsNullOrWhiteSpace(roomsResourceParameters.SearchQuery)) { var searchQuery = roomsResourceParameters.SearchQuery.Trim(); collection = collection.Where(r => r.Description.Contains(searchQuery)); } return(await collection.ToListAsync()); }
protected bool BeAValidDates(DatesDTO dates) { return(_bookingsRepository.AreDatesCorrect(dates)); }