public Aircraftschedule MaptobookingVM(Aircraftschedule booking) { Aircraftschedule customerid = new Aircraftschedule(); customerid.CustomerID = (int)HttpContext.Session.GetInt32("id"); Aircraftschedule bookingVM = new Aircraftschedule { BookingID = booking.BookingID, CustomerID = customerid.CustomerID, ScheduleID = booking.ScheduleID, PassengerName = booking.PassengerName, PassportNumber = booking.PassportNumber, Nationality = booking.Nationality, FlightNumber = booking.FlightNumber, DepartureCity = booking.DepartureCity, DepartureCountry = booking.DepartureCountry, DepartureDateTime = booking.DepartureDateTime, ArrivalCity = booking.ArrivalCity, ArrivalCountry = booking.ArrivalCountry, ArrivalDateTime = booking.ArrivalDateTime, FlightDuration = booking.FlightDuration, SeatClass = booking.SeatClass, AmtPayable = booking.AmtPayable, Remarks = booking.Remarks, DateTimeCreated = booking.DateTimeCreated, EconomyClassPrice = booking.EconomyClassPrice, BusinessClassPrice = booking.BusinessClassPrice, Status = booking.Status }; return(bookingVM); }
// GET: About Us public IActionResult Index() { Aircraftschedule aboutus = new Aircraftschedule(); ViewData["DestinationList"] = GetDestination(); return(View(aboutus)); }
public Aircraftschedule GetDetails(int bookingId) { Aircraftschedule passenger = new Aircraftschedule(); //Create a SqlCommand object from connection object SqlCommand cmd = conn.CreateCommand(); //Specify the SELECT SQL statement cmd.CommandText = @"SELECT BookingID, PassengerName, PassportNumber, Nationality, FlightNumber, DepartureCity, DepartureCountry, DepartureDateTime, ArrivalCity, ArrivalCountry, ArrivalDateTime, FlightDuration, SeatClass, AmtPayable, Remarks FROM BOOKING INNER JOIN FlightSchedule ON Booking.ScheduleID = FlightSchedule.ScheduleID INNER JOIN FlightRoute ON FlightSchedule.RouteID = FlightRoute.RouteID WHERE BookingID = @selectedBookingID"; //Define the parameter used in SQL statement, value for the //parameter is retrieved from the method parameter "bookingid" cmd.Parameters.AddWithValue("@selectedBookingID", bookingId); //Open a database connection conn.Open(); //Execute SELECT SQL through a DataReader SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { //Read the record from database while (reader.Read()) { // Fill passenger object with values from the data reader passenger.BookingID = bookingId; passenger.PassengerName = reader.GetString(1); passenger.PassportNumber = reader.GetString(2); passenger.Nationality = reader.GetString(3); passenger.FlightNumber = reader.GetString(4); passenger.DepartureCity = reader.GetString(5); passenger.DepartureCountry = reader.GetString(6); passenger.DepartureDateTime = reader.GetDateTime(7); passenger.ArrivalCity = reader.GetString(8); passenger.ArrivalCountry = reader.GetString(9); passenger.ArrivalDateTime = reader.GetDateTime(10); passenger.FlightDuration = reader.GetInt32(11); passenger.SeatClass = reader.GetString(12); passenger.AmtPayable = reader.GetDecimal(13); passenger.Remarks = !reader.IsDBNull(14) ? reader.GetString(14) : null; } } //Close DataReader reader.Close(); //Close the database connection conn.Close(); return(passenger); }
// GET: BookAirTicket public IActionResult BookAirTicket(int id) { // Stop accessing the action if not logged in // or account not in the "Customer" role if ((HttpContext.Session.GetString("Role") == null) || (HttpContext.Session.GetString("Role") != "Customer")) { return(RedirectToAction("Index", "Home")); } Aircraftschedule booking = CustomerContext.GetSchedule(id); Aircraftschedule bookingVM = MaptobookingVM(booking); ViewData["CountryList"] = GetCountries(); return(View(bookingVM)); }
// MoreDetails public ActionResult MoreDetails(int id) { // Stop accessing the action if not logged in // or account not in the "Customer" role if ((HttpContext.Session.GetString("Role") == null) || (HttpContext.Session.GetString("Role") != "Customer")) { return(RedirectToAction("Index", "Home")); } Aircraftschedule passenger = CustomerContext.GetDetails(id); Aircraftschedule passengerVM = MaptopassengerVM(passenger); return(View(passengerVM)); }
public int Add(Aircraftschedule booking) { //Create a SqlCommand object from connection object SqlCommand cmd = conn.CreateCommand(); //Specify an INSERT SQL statement which will return the auto-generated CustomerID after insertion cmd.CommandText = @"INSERT INTO Booking (CustomerID, ScheduleID, PassengerName, PassportNumber, Nationality, SeatClass, AmtPayable, Remarks, DateTimeCreated) OUTPUT INSERTED.BookingID VALUES(@CustomerID, @ScheduleID, @PassengerName, @PassportNumber, @Nationality, @SeatClass, @AmtPayable, @Remarks, @DateTimeCreated)"; //Define the parameters used in SQL statement, value for each parameter //is retrieved from respective class's property. if (booking.Remarks == null) { cmd.Parameters.AddWithValue("@Remarks", DBNull.Value); } else { cmd.Parameters.AddWithValue("@Remarks", booking.Remarks); } if (booking.SeatClass == "Economy") { cmd.Parameters.AddWithValue("@AmtPayable", booking.EconomyClassPrice); } else { cmd.Parameters.AddWithValue("@AmtPayable", booking.BusinessClassPrice); } cmd.Parameters.AddWithValue("@CustomerID", booking.CustomerID); cmd.Parameters.AddWithValue("@ScheduleID", booking.ScheduleID); cmd.Parameters.AddWithValue("@PassengerName", booking.PassengerName); cmd.Parameters.AddWithValue("@PassportNumber", booking.PassportNumber); cmd.Parameters.AddWithValue("@Nationality", booking.Nationality); cmd.Parameters.AddWithValue("@SeatClass", booking.SeatClass); cmd.Parameters.AddWithValue("@DateTimeCreated", booking.DateTimeCreated); //A connection to database must be opened before any operations made. conn.Open(); //ExecuteScalar is used to retrieve the auto-generated CustomerID after executing the INSERT SQL statement booking.BookingID = (int)cmd.ExecuteScalar(); //A Connection should be closed after operations. conn.Close(); //Return id when no error occurs. return(booking.BookingID); }
public Aircraftschedule GetSchedule(int ScheduleId) { Aircraftschedule passenger = new Aircraftschedule(); //Create a SqlCommand object from connection object SqlCommand cmd = conn.CreateCommand(); //Specify the SELECT SQL statement cmd.CommandText = @"SELECT ScheduleID, DepartureCity, DepartureCountry, ArrivalCity, ArrivalCountry, DepartureDateTime, ArrivalDateTime, EconomyClassPrice, BusinessClassPrice, Status FROM FlightRoute INNER JOIN FlightSchedule ON FlightRoute.RouteID = FlightSchedule.RouteID WHERE DepartureDateTime > DATEADD(DAY, 1, GETDATE()) AND ScheduleID = @selectedScheduleID"; //Define the parameter used in SQL statement, value for the //parameter is retrieved from the method parameter "bookingid" cmd.Parameters.AddWithValue("@selectedScheduleID", ScheduleId); //Open a database connection conn.Open(); //Execute SELECT SQL through a DataReader SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { //Read the record from database while (reader.Read()) { // Fill passenger object with values from the data reader passenger.ScheduleID = ScheduleId; passenger.DepartureCity = reader.GetString(1); passenger.DepartureCountry = reader.GetString(2); passenger.ArrivalCity = reader.GetString(3); passenger.ArrivalCountry = reader.GetString(4); passenger.DepartureDateTime = reader.GetDateTime(5); passenger.ArrivalDateTime = reader.GetDateTime(6); passenger.EconomyClassPrice = reader.GetDecimal(7); passenger.BusinessClassPrice = reader.GetDecimal(8); } } //Close DataReader reader.Close(); //Close the database connection conn.Close(); return(passenger); }
public ActionResult BookAirTicket(Aircraftschedule booking) { //Get country list for drop-down list //in case of the need to return to index.cshtml view ViewData["CountryList"] = GetCountries(); if (ModelState.IsValid) { //Add customer record to database int customerid = (int)HttpContext.Session.GetInt32("id"); CustomerContext.Add(booking); TempData["Newbooking"] = "New Booking have been successfully created!"; return(RedirectToAction("ViewAirTicket")); } else { //Input validation fails, return to the register view to display error message return(View(booking)); } }
public Aircraftschedule MaptopassengerVM(Aircraftschedule passenger) { Aircraftschedule passengerVM = new Aircraftschedule { BookingID = passenger.BookingID, PassengerName = passenger.PassengerName, PassportNumber = passenger.PassportNumber, Nationality = passenger.Nationality, FlightNumber = passenger.FlightNumber, DepartureCity = passenger.DepartureCity, DepartureCountry = passenger.DepartureCountry, DepartureDateTime = passenger.DepartureDateTime, ArrivalCity = passenger.ArrivalCity, ArrivalCountry = passenger.ArrivalCountry, ArrivalDateTime = passenger.ArrivalDateTime, FlightDuration = passenger.FlightDuration, SeatClass = passenger.SeatClass, AmtPayable = passenger.AmtPayable, Remarks = passenger.Remarks }; return(passengerVM); }