// FLIGHT EDIT'S VIEW public ActionResult FlightEdit(string id) { if (IsLoggedIn()) { var f = FlightDAO.GetFlight(id); if (f != null) { ViewBag.RouteData = RouteDAO.GetRouteList(); return(View(f)); } } return(RedirectToAction("Index")); }
// GET: Transport/Details/5 public ActionResult Details(int id) { return(View(Fdao.GetFlight(id))); }
// Function that process Payment request // Will return "ok:[orderid]" if success // Will return any other error string when failed public static string ProcessPayment(Payment payment, bool isBlocked) { db = new AirlineDBEntities(); // Checking Creditcard CreditCard card = db.CreditCard.FirstOrDefault(c => c.CCNo == payment.CCNo); if (!isBlocked) { if (card == null || card.CVV != payment.CVV) { return("Error: Credit Card is not valid."); } if (card.Balance < payment.Total) { return("Error: Not enough money in account."); } } string s = ""; try { // Create Order DateTime now = DateTime.Now; string OrderIDStr = "" + now.Year + now.Month + now.Day + now.Hour + now.Minute + now.Second; Int64 OrderID = Int64.Parse(OrderIDStr); double Total = 0; Order order = new Order(); order.OrderID = OrderID; order.OrderDate = now; if (isBlocked) { order.Status = 0; } else { order.Status = 1; } order.UserID = payment.UserID; order.Total = Total; db.Order.Add(order); int ticketCount = 1; // Create Oneway / First Flight/ First Stop Ticket Flight FInfo1 = FlightDAO.GetFlight(payment.FNo1); payment.Passengers.ForEach(p => { Ticket ticket = new Ticket(); Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount); double price = 0; if (p.Age >= 14) { price += FInfo1.BasePrice + FInfo1.Route.Aircraft.ServiceFee; } else { price += FInfo1.BasePrice * 70 / 100 + FInfo1.Route.Aircraft.ServiceFee; } double daysToDeparture = (FInfo1.DepartureTime - DateTime.Now).TotalDays; if (daysToDeparture <= 14) { if (p.Age >= 14) { price += FInfo1.BasePrice * 0.02 * (14 - daysToDeparture); } else { price += FInfo1.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture); } } foreach (var item in p.Service) { price += ServiceDAO.GetService(item).ServiceFee; db.TicketService.Add(new TicketService { ServiceID = item, TicketID = TicketID }); } if (payment.Class == "F") { price += 20; } else if (payment.Class == "B") { price += 10; } ticket.TicketID = TicketID; ticket.OrderID = OrderID; ticket.FNo = FInfo1.FNo; ticket.PassportNo = p.PassportNo; ticket.Class = payment.Class; ticket.Firstname = p.Firstname; ticket.Lastname = p.Lastname; ticket.Sex = p.Sex; ticket.Age = p.Age; ticket.IsReturn = false; ticket.Price = price; db.Ticket.Add(ticket); Total += price; ticketCount++; }); // Create Second stop's ticket (if exists) Flight FInfo2 = FlightDAO.GetFlight(payment.FNo2); if (FInfo2 != null) { payment.Passengers.ForEach(p => { Ticket ticket = new Ticket(); Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount); double price = 0; if (p.Age >= 14) { price += FInfo2.BasePrice + FInfo2.Route.Aircraft.ServiceFee; } else { price += FInfo2.BasePrice * 70 / 100 + FInfo2.Route.Aircraft.ServiceFee; } double daysToDeparture = (FInfo2.DepartureTime - DateTime.Now).TotalDays; if (daysToDeparture <= 14) { if (p.Age >= 14) { price += FInfo2.BasePrice * 0.02 * (14 - daysToDeparture); } else { price += FInfo2.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture); } } foreach (var item in p.Service) { price += ServiceDAO.GetService(item).ServiceFee; db.TicketService.Add(new TicketService { ServiceID = item, TicketID = TicketID }); } if (payment.Class == "F") { price += 20; } else if (payment.Class == "B") { price += 10; } ticket.TicketID = TicketID; ticket.OrderID = OrderID; ticket.FNo = FInfo2.FNo; ticket.PassportNo = p.PassportNo; ticket.Class = payment.Class; ticket.Firstname = p.Firstname; ticket.Lastname = p.Lastname; ticket.Sex = p.Sex; ticket.Age = p.Age; ticket.IsReturn = false; ticket.Price = price; db.Ticket.Add(ticket); Total += price; ticketCount++; }); } // Create Return Flight Ticket Flight ReFInfo = FlightDAO.GetFlight(payment.ReFNo); if (ReFInfo != null) { payment.Passengers.ForEach(p => { Ticket ticket = new Ticket(); Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount); double price = 0; if (p.Age >= 14) { price += ReFInfo.BasePrice + ReFInfo.Route.Aircraft.ServiceFee; } else { price += ReFInfo.BasePrice * 70 / 100 + ReFInfo.Route.Aircraft.ServiceFee; } double daysToDeparture = (ReFInfo.DepartureTime - DateTime.Now).TotalDays; if (daysToDeparture <= 14) { if (p.Age >= 14) { price += ReFInfo.BasePrice * 0.02 * (14 - daysToDeparture); } else { price += ReFInfo.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture); } } foreach (var item in p.Service) { price += ServiceDAO.GetService(item).ServiceFee; db.TicketService.Add(new TicketService { ServiceID = item, TicketID = TicketID }); } if (payment.Class == "F") { price += 20; } else if (payment.Class == "B") { price += 10; } ticket.TicketID = TicketID; ticket.OrderID = OrderID; ticket.FNo = ReFInfo.FNo; ticket.PassportNo = p.PassportNo; ticket.Class = payment.Class; ticket.Firstname = p.Firstname; ticket.Lastname = p.Lastname; ticket.Sex = p.Sex; ticket.Age = p.Age; ticket.IsReturn = true; ticket.Price = price; db.Ticket.Add(ticket); Total += price; ticketCount++; }); } db.SaveChanges(); db.Order.FirstOrDefault(o => o.OrderID == OrderID).Total = Total; // Seat Calculation var SFInfo1 = db.Flight.Where(f => f.FNo == payment.FNo1).FirstOrDefault(); var SFInfo2 = db.Flight.Where(f => f.FNo == payment.FNo2).FirstOrDefault(); var SReFInfo = db.Flight.Where(f => f.FNo == payment.ReFNo).FirstOrDefault(); if (payment.Class == "F") { SFInfo1.AvailSeatsF = SFInfo1.AvailSeatsF - payment.Passengers.Count(); if (SFInfo2 != null) { SFInfo2.AvailSeatsF = SFInfo2.AvailSeatsF - payment.Passengers.Count(); } if (SReFInfo != null) { SReFInfo.AvailSeatsF = SReFInfo.AvailSeatsF - payment.Passengers.Count(); } } else if (payment.Class == "B") { SFInfo1.AvailSeatsB = SFInfo1.AvailSeatsB - payment.Passengers.Count(); if (SFInfo2 != null) { SFInfo2.AvailSeatsB = SFInfo2.AvailSeatsB - payment.Passengers.Count(); } if (SReFInfo != null) { SReFInfo.AvailSeatsB = SReFInfo.AvailSeatsB - payment.Passengers.Count(); } } else { SFInfo1.AvailSeatsE = SFInfo1.AvailSeatsE - payment.Passengers.Count(); if (SFInfo2 != null) { SFInfo2.AvailSeatsE = SFInfo2.AvailSeatsE - payment.Passengers.Count(); } if (SReFInfo != null) { SReFInfo.AvailSeatsE = SReFInfo.AvailSeatsE - payment.Passengers.Count(); } } db.SaveChanges(); // Skymile if (order.Status == 1) { int dis1 = 0; int dis2 = 0; int reDis = 0; var objD1 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo1.Route.Departure && fd.AirportID2 == FInfo1.Route.Destination).FirstOrDefault(); if (objD1 == null) { objD1 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo1.Route.Destination && fd.AirportID2 == FInfo1.Route.Departure).FirstOrDefault(); } dis1 = objD1.Distance * payment.Passengers.Count(); if (FInfo2 != null) { var objD2 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo2.Route.Departure && fd.AirportID2 == FInfo2.Route.Destination).FirstOrDefault(); if (objD2 == null) { objD2 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo2.Route.Destination && fd.AirportID2 == FInfo2.Route.Departure).FirstOrDefault(); } dis2 = objD2.Distance * payment.Passengers.Count(); } if (ReFInfo != null) { var objReD = db.FlightDistance.Where(fd => fd.AirportID1 == ReFInfo.Route.Departure && fd.AirportID2 == ReFInfo.Route.Destination).FirstOrDefault(); if (objReD == null) { objReD = db.FlightDistance.Where(fd => fd.AirportID1 == ReFInfo.Route.Destination && fd.AirportID2 == ReFInfo.Route.Departure).FirstOrDefault(); } reDis = objReD.Distance * payment.Passengers.Count(); } db.User.FirstOrDefault(u => u.UserID == order.UserID).Skymiles += dis1 + dis2 + reDis; } db.SaveChanges(); // Charging creditcard if (!isBlocked) { card.Balance = card.Balance - Total; } // Saving changes db.SaveChanges(); return("ok:" + OrderID); } catch (Exception e) { return(e.Message); } }