public ActionResult MakeBooking(MakeBookingViewModel model)
        {
            var userId       = User.Identity.GetUserId();
            var customerUser = db.Users.Find(userId);

            DateTime?bookingStart = model.BookingStartDate;
            DateTime?bookingEnd   = model.BookingEndDate;

            ViewBag.VehicleCategories = new SelectList(db.VehicleCategories, "VehicleCategoryID", "VehicleCategoryCode");

            if (model != null && ModelState.IsValid)
            {
                ViewBag.Message = "Make Booking";

                var newBooking = new MakeBookingViewModel()
                {
                    BookingStartDate  = bookingStart,
                    BookingEndDate    = bookingEnd,
                    Vehicles          = model.Vehicles,
                    VehicleCategories = model.VehicleCategories,
                    MemberID          = model.MemberID,
                };
            }

            return(View("~/Views/Booking/MakeBooking.cshtml", model));
        }
Пример #2
0
        public async Task <IActionResult> BookHotel(int?id, string checkIn, string checkOut, int adults, int children)
        {
            try
            {
                var checkInDateTemp  = DateTime.ParseExact(checkIn, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                var checkOutDateTemp = DateTime.ParseExact(checkOut, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException("Invalid dates!");
            };

            // Validate the dates parsing if the user modified the URL


            var checkInDate  = DateTime.ParseExact(checkIn, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            var checkOutDate = DateTime.ParseExact(checkOut, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            int nightsStay   = (checkOutDate - checkInDate).Days;

            if (checkOutDate <= checkInDate || id == null || adults == 0 || checkInDate == checkOutDate || checkInDate == null || checkOutDate == null)
            {
                throw new ArgumentOutOfRangeException("Invalid input data! Check out date should be after the check in date! Minimum number of adults is one! Hotel indentifier is required!");
                //Additional validation for all required parameters
            }

            var hotelQuery = await hotelService.FindHotelById(id);

            var selectedHotel = hotelQuery.FirstOrDefault();

            var bookHotelViewModel = new MakeBookingViewModel()
            {
                HotelId        = selectedHotel.Id,
                HotelName      = selectedHotel.Name,
                CheckIn        = checkIn,
                CheckOut       = checkOut,
                Adults         = adults,
                Children       = children,
                NumberOfNights = nightsStay,
                RoomsGroup     = selectedHotel.Rooms
                                 .GroupBy(r => new { r.RoomType, r.Price, r.Smoking })
                                 .Select(g => g.First()),

                // Sorting and grouping the rooms to filter all rooms by room type, price and if they are smoking or non smoking
                RoomsAvailability = selectedHotel.Rooms
                                    .Where(room => room.Stays.All(res => res.DepartureDate <= checkInDate || res.ArrivalDate >= checkOutDate)),

                // Gets all the rooms which are available
            };


            return(this.View(bookHotelViewModel));
        }
Пример #3
0
        // GET: Bookings/Create
        //returns the make booking page
        public ActionResult MakeBooking()
        {
            MakeBookingViewModel booking = new MakeBookingViewModel();

            return(View(booking));
        }