예제 #1
0
        public InternalRequestHandlerFactory(BookingRepository bookingRepository, RoomRepository roomRepository)
        {
            _bookingRepository = bookingRepository;
            _roomRepository    = roomRepository;
            _handlers          = new Dictionary <string, Func <IInternalRequestHandler> >();

            _handlers.Add("listrooms", () => { return(new AliceListRoomsRequestHandler(_roomRepository)); });
            _handlers.Add("listbookings", () => { return(new AliceBookingListRequestHandler(_bookingRepository)); });
            _handlers.Add("listmybookings", () => { return(new AliceMyBookingListRequestHandler(_bookingRepository)); });
            _handlers.Add("bookroom", () => { return(new AliceBookRoomRequestHandler(_bookingRepository)); });
            _handlers.Add("cancelbooking", () => { return(new AliceCancelBookingRequestHandler(_bookingRepository)); });
            _handlers.Add("suggestcancellations", () => { return(new AliceCancelBookingSuggestionRequestHandler(_bookingRepository)); });
            _handlers.Add("unrecognized", () => { return(new AliceUnrecognizedRequestHandler()); });
        }
예제 #2
0
        private Room GetAnyAvailableRoom(IList <Booking> bookings, DateTime dateFrom, DateTime dateTo)
        {
            RoomRepository roomRepository = new RoomRepository(_roomsDataFile);
            IList <Room>   rooms          = roomRepository.List();

            foreach (Room room in rooms)
            {
                if (!room.ExplicitBooking)
                {
                    Booking booking = GetBooking(bookings, dateFrom, dateTo, room.Name);
                    if (booking == null)
                    {
                        return(room);
                    }
                }
            }

            return(null);
        }
예제 #3
0
        private BookingRequest PrepareBookingRequest(IList <Booking> bookings, BookingRequest bookingRequest)
        {
            BookingRequest resultingRequest = bookingRequest.Clone();

            resultingRequest.BookToUtc = resultingRequest.BookToUtc.AddMilliseconds(-1);

            RoomRepository          roomRepository = new RoomRepository(_roomsDataFile);
            BookingRequestValidator validator      = new BookingRequestValidator(roomRepository);

            if (!validator.Validate(resultingRequest))
            {
                throw new Exception(validator.ValidationError);
            }

            if (resultingRequest.ExplicitBooking)
            {
                Booking presentBooking = GetBooking(bookings, bookingRequest.BookFromUtc, bookingRequest.BookToUtc, bookingRequest.RoomName);
                if (presentBooking != null)
                {
                    if (presentBooking.BookedBy.Equals(resultingRequest.BookedBy, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new Exception("It was booked by you already.");
                    }
                    else
                    {
                        throw new Exception(string.Format("Oh boy! Its not availablle. <a {{aliceRequestAct}}>Show bookings</a>", presentBooking.RoomName));
                    }
                }
            }
            else
            {
                Room room = GetAnyAvailableRoom(bookings, resultingRequest.BookFromUtc, resultingRequest.BookToUtc);
                if (room == null)
                {
                    throw new Exception("Oh boy! Hatter left no room for you.");
                }

                resultingRequest.RoomName = room.Name;
            }

            return(resultingRequest);
        }
예제 #4
0
 public AliceListRoomsRequestHandler(RoomRepository roomRepository)
 {
     _roomRepository = roomRepository;
 }
예제 #5
0
 public BookingRequestValidator(RoomRepository roomRepository)
 {
     _roomRepository = roomRepository;
 }