public static void InsertFlight() { db = new AirlineDBEntities(); IEnumerable <Route> routeDB = db.Route; foreach (var route in routeDB) { var aircraft = aircraftDB.Where(a => a.AircraftID == route.RAircraft).FirstOrDefault(); int seatE = aircraft.EconomySeats; int seatB = 0, seatF = 0; var distance = FlightDistanceDAO.GetFlightDistance(route.Departure.Trim(), route.Destination.Trim()); if (distance == null) { string err = string.Format("{0}:{1}-{2}", route.RNo, route.Departure, route.Destination); error.Add(new ErrorModel { Error = err }); } else { if (aircraft.BussinessSeats != null) { seatB = int.Parse(aircraft.BussinessSeats.ToString()); } if (aircraft.FirstClassSeats != null) { seatF = int.Parse(aircraft.FirstClassSeats.ToString()); } for (int i = 0; i < 20; i++) { var dist = int.Parse(distance.Distance.ToString()); Flight f = new Flight(); f.FNo = RandomFNo(route.RAirline); f.RNo = route.RNo; f.AvailSeatsE = seatE; f.AvailSeatsB = seatB; f.AvailSeatsF = seatF; f.BasePrice = RandomBasePrice(dist); var departureTime = RandomDepartureTime(); f.DepartureTime = departureTime; var arrivalTime = DateTime.Parse(departureTime.ToString()); f.ArrivalTime = arrivalTime.AddMinutes(MinutesToAdd(dist)); f.FlightTime = (f.ArrivalTime - f.DepartureTime).TotalHours; FlightDAO.AddFlight(f); } } } }
public static void InsertFlightsIntoRoute(int RNo, int month) { db = new AirlineDBEntities(); Route route = db.Route.Where(item => item.RNo == RNo).FirstOrDefault(); int totalDate = DateTime.DaysInMonth(2019, month); var aircraft = aircraftDB.Where(a => a.AircraftID == route.RAircraft).FirstOrDefault(); int seatE = aircraft.EconomySeats; int seatB = 0; int seatF = 0; if (aircraft.BussinessSeats != null) { seatB = int.Parse(aircraft.BussinessSeats.ToString()); } if (aircraft.FirstClassSeats != null) { seatF = int.Parse(aircraft.FirstClassSeats.ToString()); } var distance = FlightDistanceDAO.GetFlightDistance(route.Departure.Trim(), route.Destination.Trim()); var dist = int.Parse(distance.Distance.ToString()); for (int i = 1; i <= totalDate; i++) { for (int j = 0; j < 7; j++) { var departureTime = RandomDepartureTime(i, month); var arrivalTime = DateTime.Parse(departureTime.ToString()).AddMinutes(MinutesToAdd(dist)); Flight f = new Flight { FNo = RandomFNo(route.RAirline), RNo = route.RNo, AvailSeatsE = seatE, AvailSeatsB = seatB, AvailSeatsF = seatF, BasePrice = RandomBasePrice(dist), DepartureTime = departureTime, ArrivalTime = arrivalTime }; f.FlightTime = (f.ArrivalTime - f.DepartureTime).TotalHours; FlightDAO.AddFlight(f); } } }