コード例 #1
0
ファイル: RoomService.cs プロジェクト: HasanKumas/Hotel
        //GET All Rooms list
        public async Task <IList <RoomDetailViewModel> > AllRooms()
        {
            var result = await _roomsRepository.AllRooms();

            var mappedResult = _mapper.Map <IList <RoomDetailViewModel> >(result);

            return(mappedResult.ToList());
        }
コード例 #2
0
        //Get available Rooms
        public async Task <IList <RoomDetailViewModel> > GetAvailableRooms(ReservationDetailViewModel currentReservation)
        {
            var rooms = _mapper.Map <IList <RoomDetailViewModel> >(await _roomsRepository.AllRooms()).ToList();

            //adjust the size to include rooms with range like 3-4 persons and 5-6 persons
            var size = 0;

            switch (currentReservation.NumberOfGuests)
            {
            case 1:
            {
                size = 1;
                break;
            }

            case 2:
            {
                size = 2;
                break;
            }

            case 3:
            {
                size = 4;
                break;
            }

            case 4:
            {
                size = 4;
                break;
            }

            case 5:
            {
                size = 6;
                break;
            }

            default:
            {
                size = currentReservation.NumberOfGuests;
                break;
            }
            }

            List <RoomDetailViewModel> availableRooms = rooms.Where(room => ((int)room.RoomSize).Equals(size))
                                                        .Where(room => room.EntranceAvailableDate <= currentReservation.CheckInDate)
                                                        .Where(room => room.Maintenances == null ||
                                                               room.Maintenances.All(maintenance => maintenance.StartDate >= currentReservation.CheckOutDate ||
                                                                                     maintenance.EndDate <= currentReservation.CheckInDate))
                                                        .Where(room => room.Reservations == null ||
                                                               room.Reservations.All(reservation => reservation.CheckInDate >= currentReservation.CheckOutDate ||
                                                                                     reservation.CheckOutDate <= currentReservation.CheckInDate))
                                                        .ToList();

            return(availableRooms);
        }