Exemplo n.º 1
0
 public ActionResult Index(Booking booking)
 {
     BLLServiceGateway<Booking> gate = new BLLServiceGateway<Booking>();
     booking.Nowday = DateTime.Now;
     gate.PostItems("api/Booking/", booking);
     return RedirectToAction("Index");
 }
        public IView Book(int roomId, DateTime startDate, DateTime endDate, string comments)
        {
            this.Authorize(Role.User, Role.VenueAdmin);
            var room = this.Data.Rooms.Get(roomId);
            if (room == null)
            {
                return this.NotFound(string.Format("The room with ID {0} does not exist.", roomId));
            }

            Validator.ValidateDateRange(startDate, endDate);

            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);
        }
Exemplo n.º 3
0
        public IHttpActionResult PostBooking(Booking booking)
        {
            DALServiceGateway<Booking> gate = new DALServiceGateway<Booking>();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            gate.PostItems("api/Booking/", booking);
            return CreatedAtRoute("DefaultApi", new { id = booking.Id }, booking);
        }
        public IView Book(int roomId, DateTime startDate, DateTime endDate, string comments)
        {
            this.Authorize(Roles.User, Roles.VenueAdmin);

            var room = this.Data.RoomsRepository.Get(roomId);
            if (room == null)
            {
                return this.NotFound(string.Format(Constants.RoomWithIdNotExistMsg, roomId));
            }

            var availablePeriod = room.AvailableDates.FirstOrDefault(d => d.StartDate <= startDate && d.EndDate >= endDate);
            if (availablePeriod == null)
            {
                throw new ArgumentException(string.Format(Constants.InvalidRoomForPeriodMsg, 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);
        }
Exemplo n.º 5
0
 public Book(Booking booking)
     : base(booking)
 {
 }
Exemplo n.º 6
0
        private IView Book(int roomId, DateTime startDate, DateTime endDate, string comments)
        {
            this.Authorize(Roles.User, Roles.VenueAdmin);
            var room = Data.RepositoryWithRooms.Get(roomId);
            if (room == null)
            {
                return this.NotFound($"The room with ID {roomId} does not exist.");
            }

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

            var availablePeriod = room.AvailableDates.FirstOrDefault(d => d.StartDate <= startDate || d.EndDate >= endDate);
            if (availablePeriod == null)
            {
                throw new ArgumentException(
                    $"The room is not available to book in the period {startDate:dd.MM.yyyy} - {endDate:dd.MM.yyyy}.");
            }

            decimal totalPrice = (endDate - startDate).Days * room.PricePerDay;
            var booking = new Booking(
                CurrentUser, 
                startDate, 
                endDate, 
                totalPrice, 
                comments);
            room.Bookings.Add(booking);
            CurrentUser.Bookings.Add(booking);
            this.UpdateRoomAvailability(startDate, endDate, room, availablePeriod);
            return this.View(booking);
        }