private static void SearchFlight(Dictionary<FlightStatus, string> statusDictionary, Flight[] flightsList) { Console.WriteLine("Please choose number of command printed below"); Console.WriteLine("0 - Search by flight number"); Console.WriteLine("1 - Search by date"); Console.WriteLine("2 - Search by city"); Console.WriteLine("3 - Search of the flight which is the nearest (1 hour)\n to the specified time"); Console.WriteLine("4 - Return to main menu"); int command; while (!int.TryParse(Console.ReadLine(), out command)) { Console.WriteLine("Please enter correct number of command printed below"); } switch (command) { case 0: { int flightNumber; Console.WriteLine("Please enter flight number to search"); if (!int.TryParse(Console.ReadLine(), out flightNumber)) { Console.WriteLine("Wrong input value! Please enter flight number"); } var flight = flightsList.FirstOrDefault(x => x.FlightNumber == flightNumber); Console.WriteLine(flight.ToString()); } break; case 1: { Console.WriteLine("Please enter the date and time of the flight."); DateTime dateTime; while (!DateTime.TryParse(Console.ReadLine(), out dateTime)) { Console.WriteLine( "Please enter correct date and time of the flight."); } var flights = flightsList.Select(x => x.Date == dateTime); foreach (var flight in flights) { Console.WriteLine(flight.ToString()); } } break; case 2: { Console.WriteLine("Please enter city to search"); var city = Console.ReadLine(); var flights = flightsList.Select(x => x.City == city); foreach (var flight in flights) { Console.WriteLine(flight.ToString()); } } break; case 3: { var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, (DateTime.Now.Hour + 1), 0, 0); var flight = flightsList.FirstOrDefault(x => (x.Date >= DateTime.Now) & (x.Date <= dt)); if (flight.FlightStatus == FlightStatus.undefined) { Console.WriteLine("Please enter the date and time of the flight."); DateTime dateTime; while (!DateTime.TryParse(Console.ReadLine(), out dateTime)) { Console.WriteLine( "Please enter correct date and time of the flight."); } var customDate = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, (dateTime.Hour + 1), 0, 0); var customFlights = flightsList.Where(x => (x.Date >= dateTime) & (x.Date <= customDate)).Select(x => x); foreach (var customFlight in customFlights.Where(customFlight => customFlight.FlightStatus != FlightStatus.undefined)) { Console.WriteLine(customFlight.ToString()); } } else { Console.WriteLine(flight.ToString()); } } break; case 4: return; default: return; ; } }
private static void EditFlight(Dictionary<FlightStatus, string> statusDictionary, Flight[] flightsList) { Console.WriteLine("You are going to edit a flight."); int flightNumber; Console.WriteLine("Please enter flight number"); if (!int.TryParse(Console.ReadLine(), out flightNumber)) { Console.WriteLine("Wrong input value! Please enter flight number"); } var flightToUpdate = flightsList.FirstOrDefault(x => x.FlightNumber == flightNumber); Console.WriteLine("Below current info about flight"); Console.WriteLine(flightToUpdate.ToString()); Console.WriteLine("Please enter new value for airline"); var airline = Console.ReadLine(); Console.WriteLine("Please enter new value for city"); var city = Console.ReadLine(); Console.WriteLine("Please enter new value for terminal"); var terminal = Console.ReadLine(); Console.WriteLine("Please enter new value for gate"); int gate; while (!int.TryParse(Console.ReadLine(), out gate)) { Console.WriteLine("Wrong input value! Please enter the gate"); } Console.WriteLine("Please choose the current status of the flight"); foreach (var item in statusDictionary.OrderBy(x => (int) x.Key)) { Console.WriteLine("{0} - {1}", (int) item.Key, item.Value); } FlightStatus status; while (!Enum.TryParse(Console.ReadLine(), out status)) { Console.WriteLine("Wrong input value! Please enter the current status of the flight"); } Console.WriteLine( "Please enter the date and time of the flight."); DateTime dateTime; while (!DateTime.TryParse(Console.ReadLine(), out dateTime)) { Console.WriteLine("Please enter correct date and time of the flight."); } for (var i = 0; i < flightsList.Length; i++) { if (flightsList[i].FlightNumber == flightNumber) { flightsList[i].FlightStatus = status; flightsList[i].Gate = gate; flightsList[i].Airline = airline; flightsList[i].City = city; flightsList[i].Terminal = terminal; flightsList[i].Date = dateTime; break; } } }