Example #1
0
        internal void HandleFlightList(List <Flight> flights, string description)
        {
            bool   parseIsOk;
            int    numOfItemToEdit;
            string usersChoice = string.Empty;

            while (true)
            {
                Console.Clear();
                itemsPrinter.PrintItemsList(flights, 0, description);
                Console.Write($"1 - Edit Flight\n2 - Add Flight\n3 - Delete Flight\n0 - Exit to previous Menu\nYour choice: ");

                parseIsOk = Int32.TryParse(Console.ReadLine(), out numOfItemToEdit);

                if (numOfItemToEdit == 0 && parseIsOk)
                {
                    return;
                }
                if (!parseIsOk || numOfItemToEdit < 0 || numOfItemToEdit > 3)
                {
                    usersChoice = ReceiveUserChoice();
                    if (usersChoice == "1")
                    {
                        break;
                    }
                    if (usersChoice == "2")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
                //Edit Passenger
                switch (numOfItemToEdit)
                {
                case 1:
                    //Editing flights
                    EditFlightsList(flights, description);
                    break;

                //Adding flight
                case 2:
                    try
                    {
                        flights.Add(new Flight(new Random()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                //Deleting flights
                case 3:
                    try
                    {
                        Console.Write("Enter number...   ");
                        flights.Remove(flights[int.Parse(Console.ReadLine()) - 1]);
                    }
                    catch (Exception e)
                    {
                        usersChoice = ReceiveUserChoice();
                        if (usersChoice == "1")
                        {
                            break;
                        }
                        if (usersChoice == "2")
                        {
                            return;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    break;

                default:
                    usersChoice = ReceiveUserChoice();
                    if (usersChoice == "1")
                    {
                        break;
                    }
                    if (usersChoice == "2")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
Example #2
0
        internal void HandlePassengerList(List <Passenger> passengers, string description)
        {
            bool   parseIsOk;
            int    numOfItemToEdit;
            string usersChoice = string.Empty;

            while (true)
            {
                Console.Clear();
                itemsPrinter.PrintItemsList(passengers, 0, description);
                Console.Write($"1 - Edit Passenger\n2 - Add Passenger\n3 - Delete Passenger\n0 - Exit to previous Menu\nYour choice: ");

                parseIsOk = Int32.TryParse(Console.ReadLine(), out numOfItemToEdit);

                if (numOfItemToEdit == 0 && parseIsOk)
                {
                    return;
                }
                if (!parseIsOk || numOfItemToEdit < 0 || numOfItemToEdit > 3)
                {
                    usersChoice = ReceiveUserChoice();
                    if (usersChoice == "1")
                    {
                        break;
                    }
                    if (usersChoice == "2")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
                //Edit Passenger
                switch (numOfItemToEdit)
                {
                //Edit passengers
                case 1:
                    EditPassengerList(passengers, description);
                    break;

                //Adding Passenger
                case 2:
                    try
                    {
                        passengers.Add(new Passenger(new Random(), passengers[0].PassFlight));
                    }
                    catch
                    {
                        throw new NotFiniteNumberException();
                    }
                    break;

                //Deleting Passenger
                case 3:
                    try
                    {
                        Console.Write("Enter number...   ");
                        passengers.Remove(passengers[int.Parse(Console.ReadLine()) - 1]);
                    }
                    catch (Exception e)
                    {
                        usersChoice = ReceiveUserChoice();
                        if (usersChoice == "1")
                        {
                            break;
                        }
                        if (usersChoice == "2")
                        {
                            return;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    break;

                default:
                    usersChoice = ReceiveUserChoice();
                    if (usersChoice == "1")
                    {
                        break;
                    }
                    if (usersChoice == "2")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }