public async Task <IEnumerable <Room> > GetAllAvailableRoomsAsync(AvailableRoomParameters roomParameters, bool trackChanges) => await FindByCondition(r => !r.Bookings.Any(b => (b.Start > roomParameters.Start && b.Start < roomParameters.End) || (b.End > roomParameters.Start && b.End < roomParameters.End)), trackChanges) .OrderBy(r => r.Number) .Skip((roomParameters.PageNumber - 1) * roomParameters.PageSize) .Take(roomParameters.PageSize) .ToListAsync();
public async Task <IActionResult> GetAvailableRooms([FromQuery] AvailableRoomParameters roomParameters) { if (!roomParameters.ValidDateRange) { return(BadRequest(new { message = "Start date can't be earlier than end date." })); } var rooms = await _repository.Room.GetAllAvailableRoomsAsync(roomParameters, trackChanges : false); if (rooms.Count() == 0) { return(NoContent()); } var roomsDto = _mapper.Map <IEnumerable <RoomDto> >(rooms); return(Ok(roomsDto)); }