static void Menu(ref Flight[] arrival, ref Flight[] depature, ref Passenger[] people, ref List <FlightClass> f_class_list) { Console.Clear(); do { Console.WriteLine("work with: \n1) flights \n2) flight classes \n3) exit"); ConsoleKeyInfo case_switch = Console.ReadKey(); switch (case_switch.Key.ToString()) { case "D1": //arrival menu_flight(ref arrival, ref people, ref f_class_list); break; //case "D2": // menu_flight(ref depature, ref people, ref f_class_list); // break; case "D2": Console.WriteLine("\ninput the name of the flight class"); string name_f_class = Console.ReadLine(); int cost = 0; do { Console.WriteLine("input the cost"); string cost_string = Console.ReadLine(); bool check_number = int.TryParse(cost_string, out cost); if (cost == 0) { Console.WriteLine("input a number"); } }while (cost == 0); FlightClass f_class = new FlightClass(name_f_class, cost); using (var ctx = new AirplaneContext()) { ctx.FlightClasses.Add(f_class); ctx.SaveChanges(); } f_class_list.Add(f_class); break; case "D3": Environment.Exit(0); break; default: Console.WriteLine("wrong input"); break; } } while (true); }
static void menu_flight(ref Flight[] flight, ref Passenger[] people, ref List <FlightClass> f_class_list) { Console.Clear(); bool exit = true; string string_for_input; do { Console.WriteLine("1) add flight\n2) change flight \n3) delete flight \n4) search \n5) show flights \n6) set flight class \n7) view current flight class \n8) passengers \n9) back"); ConsoleKeyInfo case_switch1 = Console.ReadKey(); switch (case_switch1.Key.ToString()) { case "D1": for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == null || flight[i].Flight_num == string.Empty) { flight[i].Add_flight(); break; } } Print(flight); break; case "D2": Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("input the numbr of the flight"); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == string_for_input) { flight[i].Add_flight(); break; } } Print(flight); break; case "D3": Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("input the numbr of the flight"); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == string_for_input) { flight[i].Delete_flight(); break; } } Print(flight); break; case "D4": Search(flight); break; case "D5": Print(flight); break; case "D6": if (f_class_list.Count != 0) { Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("flight classes:"); Console.Write("{0,8:G}" + " ", "№"); Console.Write("{0,8:G}" + " ", "name"); Console.Write("{0,8:G}" + " ", "cost"); Console.WriteLine(); for (int i = 0; i < f_class_list.Count; i++) { Console.Write("{0,8:G}" + " ", i + 1); Console.Write("{0,8:G}" + " ", f_class_list[i].Name); Console.Write("{0,8:G}" + " ", f_class_list[i].Cost); Console.WriteLine(); } Console.WriteLine("input the name of the flight class"); string searched_name = Console.ReadLine(); FlightClass result = f_class_list.Find( delegate(FlightClass fc) { return(fc.Name == searched_name); } ); try { Console.WriteLine("{0} is successfully found and costs {1}", result.Name, result.Cost); } catch (NullReferenceException) { Console.WriteLine("{0} was not found", searched_name); } Print(flight); Console.WriteLine("input the numbr of the flight"); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == string_for_input) { flight[i].Flight_Class = result; } } } break; case "D7": Console.WriteLine("input the numbr of the flight"); string_for_input = Console.ReadLine(); Flight temp_flight = new Flight(); for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == string_for_input && flight[i].Flight_Class != null) { Console.WriteLine("flight class: {0}", flight[i].Flight_Class.Name); Console.WriteLine("flight price: {0}", flight[i].Flight_Class.Cost); } if (flight[i].Flight_num == string_for_input) { temp_flight = flight[i]; } } if (temp_flight.Flight_num == null) { } break; case "D8": bool passenger_exit = true; bool wrong_flight = true; Print(flight); Console.WriteLine("input the numbr of the flight"); var p_flight = new Flight(); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (flight[i].Flight_num == string_for_input) { p_flight = flight[i]; wrong_flight = false; } } if (wrong_flight) { Console.WriteLine("wrong number of the flight, try again"); break; } do { Console.WriteLine("1) add passenger\n2) change passenger \n3) delete passenger \n4) search \n5) show passengers \n6) back"); ConsoleKeyInfo case_switch_passenger = Console.ReadKey(); switch (case_switch_passenger.Key.ToString()) { case "D1": //Print(flight); Console.SetCursorPosition(0, Console.CursorTop); for (int i = 0; i < 30; i++) { if (people[i].Surname == null) { people[i].Add_passenger(p_flight); break; } } Print(people); break; case "D2": Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("input the surname of the passenger"); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (people[i].Surname == string_for_input) { people[i].Add_passenger(p_flight); break; } } Print(people); break; case "D3": Console.SetCursorPosition(0, Console.CursorTop); Console.WriteLine("input the surname of the passenger"); string_for_input = Console.ReadLine(); for (int i = 0; i < 30; i++) { if (people[i].Surname == string_for_input) { people[i].Delete_passenger(); break; } } Print(people); break; case "D4": Search(people); break; case "D5": Console.SetCursorPosition(0, Console.CursorTop); Print(people); break; case "D6": passenger_exit = false; break; } } while (passenger_exit); break; case "D9": //Menu(ref flight, ref depature, ref people,ref f_class, ref num); exit = false; break; default: Console.WriteLine("wrong input"); break; } } while (exit); }