示例#1
0
        public async Task <IEnumerable <Room> > GetFreeRoomsAsync([FromBody][Required] BookingByHotelBindingModel bookingQuery)
        {
            Task <IEnumerable <Room> > getRooms = UnitOfWork.Room.GetByHotelIdAsync(bookingQuery.HotelId.Value);
            Task <IEnumerable <RoomBookingByHotel> > getBookings = UnitOfWork.RoomBooking.GetByHotelIdAsync(bookingQuery.HotelId.Value);
            await Task.WhenAll(getRooms, getBookings);

            IEnumerable <Room> roomResult = getRooms.Result;
            List <Room>        rooms      = roomResult.ToList();

            IEnumerable <RoomBookingByHotel> bookingResult = getBookings.Result;
            List <RoomBookingByHotel>        bookings      = bookingResult.ToList().Where(b =>
                                                                                          (b.StartReserveTime >= bookingQuery.StartReserveTime &&
                                                                                           b.StartReserveTime <= bookingQuery.EndReserveTime) ||
                                                                                          (b.EndReserveTime >= bookingQuery.StartReserveTime &&
                                                                                           b.EndReserveTime <= bookingQuery.EndReserveTime))
                                                             .ToList();

            if (bookingQuery.Type != null)
            {
                rooms = rooms.Where(b => b.Type == bookingQuery.Type).ToList();
            }
            IEnumerable <Guid> bookedRoomsIds = bookings.Select(b => b.RoomId);

            return(rooms.Where(room => !bookedRoomsIds.Contains(room.Id)));
        }
示例#2
0
 public async Task <IEnumerable <Room> > GetFreeRooms([FromBody][Required] BookingByHotelBindingModel bookingQuery)
 {
     return(await hotelDAO.GetFreeRoomByHotelIdByBookingPeriodAsync(bookingQuery.HotelId, bookingQuery.StartReserveTime, bookingQuery.EndReserveTime, bookingQuery.Type));
 }