Exemple #1
0
        public async Task <IActionResult> ConfirmBooking()
        {
            //get session variable tempBookingVMDetails
            var bookingVM = _globalRepo.GetObjFromSessionJSON <BookingVM>("tempBookingVMDetails");

            //if non member make booking, set currUserId as null
            string currUserId = null;

            if (_signInManager.IsSignedIn(User))
            {
                currUserId = _userManager.GetUserId(User);
            }
            //add booking to DB and get add booking Id
            var resultId = await _bookingRepo.AddBooking(bookingVM.Booking, currUserId);

            //get all booking guests details and add to DB
            foreach (var guest in bookingVM.BookingNonMembers)
            {
                await _bookingRepo.AddBookingGuests(guest, resultId);
            }

            //update seats remain count. Assume every booking guest will result in one seat reserved, regardless whether they have checked in
            await _flightRepo.UpdateSeatsRemain(-bookingVM.BookingNonMembers.Count(), bookingVM.Booking.GoFlightId);

            await _flightRepo.UpdateSeatsRemain(-bookingVM.BookingNonMembers.Count(), bookingVM.Booking.ReturnFlightId);

            //copy added booking ID to vm
            bookingVM.Booking.ID = resultId;

            //remove session variables to release memory
            HttpContext.Session.Remove("tempBookingVMDetails");
            HttpContext.Session.Remove("tempBookingDetails");

            //return the VM to next view for display purposes
            return(View("BookingConfirmed", bookingVM));
        }