示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Customer_DetailId,Hotel_DetailId,Room_DetailId,Service_DetailId")] Booking_Detail booking_Detail)
        {
            if (id != booking_Detail.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(booking_Detail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Booking_DetailExists(booking_Detail.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Customer_DetailId"] = new SelectList(_context.Customer_Detail, "Id", "Customer_Name", booking_Detail.Customer_DetailId);
            ViewData["Hotel_DetailId"]    = new SelectList(_context.Hotel_Detail, "Id", "Branch_Name", booking_Detail.Hotel_DetailId);
            ViewData["Room_DetailId"]     = new SelectList(_context.Room_Detail, "Id", "Room_Type", booking_Detail.Room_DetailId);
            ViewData["Service_DetailId"]  = new SelectList(_context.Service_Detail, "Id", "Name", booking_Detail.Service_DetailId);
            return(View(booking_Detail));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Customer_DetailId,Hotel_DetailId,Room_DetailId,Service_DetailId")] Booking_Detail booking_Detail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking_Detail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Customer_DetailId"] = new SelectList(_context.Customer_Detail, "Id", "Customer_Name", booking_Detail.Customer_DetailId);
            ViewData["Hotel_DetailId"]    = new SelectList(_context.Hotel_Detail, "Id", "Branch_Name", booking_Detail.Hotel_DetailId);
            ViewData["Room_DetailId"]     = new SelectList(_context.Room_Detail, "Id", "Room_Type", booking_Detail.Room_DetailId);
            ViewData["Service_DetailId"]  = new SelectList(_context.Service_Detail, "Id", "Name", booking_Detail.Service_DetailId);
            return(View(booking_Detail));
        }
示例#3
0
        public ActionResult FlightBooking(FlightBookingViewModel model, string[] Name, string[] Gender, string[] Nationality, string[] DOB, string btnProceed, string btnSubmit)
        {
            string seats = Request.Form["SeatsSelected"];

            string[] seat = seats.Split(new char[] { ',' });

            if (!String.IsNullOrEmpty(btnProceed))
            {
                string bookedSeats = String.Join(",", (from b in db.Booking_Detail
                                                       join s in db.Seat_Detail on b.BookingID equals s.BookingID
                                                       where b.FlightID == model.flightID
                                                       select s.SeatID).ToArray());
                ViewBag.BookedSeats   = bookedSeats;
                ViewBag.SelectedSeats = seats;

                var flightDetail = (from f in db.Flight_Detail where f.FlightID == model.flightID select f).FirstOrDefault();
                var priceList    = (from p in db.Pricings where p.FlightID == model.flightID select p).ToList();

                var firstClassPriceList    = (from pl in priceList where pl.ClassCategory == "First" select pl).OrderBy(x => x.Price).ToList();
                var businessClassPriceList = (from pl in priceList where pl.ClassCategory == "Business" select pl).OrderBy(x => x.Price).ToList();
                var economyClassPriceList  = (from pl in priceList where pl.ClassCategory == "Economy" select pl).OrderBy(x => x.Price).ToList();

                model.numberOfSelectedSeats  = seat.Length;
                model.bookedSeats            = seat;
                model.flightDetail           = flightDetail;
                model.firstClassPriceList    = firstClassPriceList;
                model.businessClassPriceList = businessClassPriceList;
                model.economyClassPriceList  = economyClassPriceList;
                ViewBag.Disable = "disable";
            }

            if (!String.IsNullOrEmpty(btnSubmit))
            {
                Guid sessionUserID = new Guid(User.Identity.Name.Split('|')[1].ToString());

                PriceCalculation priceCalculation = new PriceCalculation();

                Booking_Detail bookingDetail = new Booking_Detail()
                {
                    BookingID          = Guid.NewGuid(),
                    FlightID           = model.flightID,
                    BookedByCustomerID = sessionUserID,
                    Amount             = priceCalculation.GetTotalPrice(DOB, seat, model.flightID),
                    BookingDateTime    = DateTime.Now
                };
                db.Booking_Detail.Add(bookingDetail);
                db.SaveChanges();

                for (int i = 0; i < seat.Length; i++)
                {
                    Seat_Detail seatDetail = new Seat_Detail()
                    {
                        TicketID  = Guid.NewGuid(),
                        BookingID = bookingDetail.BookingID,
                        SeatID    = Convert.ToInt16(seat[i])
                    };
                    db.Seat_Detail.Add(seatDetail);
                    db.SaveChanges();

                    Passenger passenger = new Passenger()
                    {
                        PassengerID = Guid.NewGuid(),
                        Name        = Name[i],
                        Gender      = Gender[i],
                        DOB         = Convert.ToDateTime(DOB[i]),
                        Nationality = Nationality[i],
                        TicketID    = seatDetail.TicketID
                    };
                    db.Passengers.Add(passenger);
                    db.SaveChanges();
                }
                return(RedirectToAction("Home", "Customer"));
            }
            return(View(model));
        }