Exemplo n.º 1
0
        public IHttpActionResult GetRoom(int number)
        {
            var room = roomProvider.GetRoom(number);

            if (room != null)
            {
                return(Ok(room));
            }
            return(NotFound());
        }
        public IHttpActionResult CreateBooking([FromBody] CreateReservation message)
        {
            var room          = roomProvider.GetRoom(message.RoomNumber);
            var user          = userProvider.GetFromUserName(new UserName(message.UserName.LastName, message.UserName.FirstName));
            var day           = Day.From(message.Hour.Date);
            var timeSlot      = day.ComputeSlots(Constraints.SlotDuration).First(s => s.Contains(message.Hour));
            var bookingResult = reservationService.BookRoom(room, user, timeSlot);

            if (bookingResult.Status == BookingStatus.Accepted)
            {
                return(Content(HttpStatusCode.Accepted, bookingResult.ReservationId));
            }

            var availableSlotStarts = reservationService.GetBookableTimeSlots(room, timeSlot).Select(s => s.Start).ToList();

            return(Content(HttpStatusCode.Conflict, availableSlotStarts));
        }