public ActionResult Book(Guid id) { var FlightID = id; var loginID = Session["loginID"]; BookFlightVM item = new BookFlightVM(); var data = db.Flights.Where(x => x.FlightID == FlightID).First(); item.FlightID = FlightID; item.Origin = data.Origin; item.Destination = data.Destination; item.DepartureTime = data.DepartureTime; item.ArrivalTime = data.ArrivalTime; return(View(item)); }
public ActionResult Book(BookFlightVM model) { Booking tbl = new Booking(); Guid loginID = (Guid)Session["loginID"]; Guid guid = Guid.NewGuid(); tbl.BookingID = guid; tbl.FlightID = model.FlightID; tbl.UserID = loginID; var tbl2 = db.Flights.Where(x => x.FlightID == model.FlightID).First(); if (tbl2.SeatRemained != 0) { tbl2.SeatRemained = tbl2.SeatRemained - 1; db.SaveChanges(); var seat = tbl2.TotalSeat - tbl2.SeatRemained; if (seat >= 1 && seat <= 3) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "A" + seatMod.ToString(); } if (seat >= 4 && seat <= 6) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "B" + seatMod.ToString(); } if (seat >= 7 && seat <= 9) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "C" + seatMod.ToString(); } if (seat >= 10 && seat <= 12) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "D" + seatMod.ToString(); } if (seat >= 13 && seat <= 15) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "E" + seatMod.ToString(); } if (seat >= 16 && seat <= 18) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "E" + seatMod.ToString(); } if (seat >= 19 && seat <= 20) { var seatMod = seat % 3; if (seatMod == 0) { seatMod = 3; } tbl.Seat = "E" + seatMod.ToString(); } } db.Bookings.Add(tbl); db.SaveChanges(); return(RedirectToAction("ViewBooking", "Booking")); }