public IView Book(int roomId, DateTime startDate, DateTime endDate, string comments)
        {
            this.Authorize(Roles.User, Roles.VenueAdmin);
            var room = this.Data.RepositoryWithRooms.Get(roomId);
            if (room == null)
            {
                return this.NotFound(string.Format("The room with ID {0} does not exist.", roomId));
            }

            if (endDate < startDate)
            {
                throw new ArgumentException("The date range is invalid.");
            }

            // BUG: dates check || to &&
            var availablePeriod =
                room.AvailableDates.FirstOrDefault(d => d.StartDate <= startDate && d.EndDate >= endDate);
            if (availablePeriod == null)
            {
                throw new ArgumentException(
                    string.Format(
                        "The room is not available to book in the period {0:dd.MM.yyyy} - {1:dd.MM.yyyy}.",
                        startDate,
                        endDate));
            }

            decimal totalPrice = (endDate - startDate).Days * room.PricePerDay;
            var booking = new Booking(this.CurrentUser, startDate, endDate, totalPrice, comments);
            room.Bookings.Add(booking);
            this.CurrentUser.Bookings.Add(booking);
            this.UpdateRoomAvailability(startDate, endDate, room, availablePeriod);
            return this.View(booking);
        }
예제 #2
0
 public Book(Booking booking)
     : base(booking)
 {
 }