Beispiel #1
0
        private void EditPassenger()
        {
            ConsoleManager.PrepareConsoleForInput();
            Console.WriteLine("Please Enter Passport series;Passport number to find a passenger");
            string[] passportInfo   = Console.ReadLine().Split(';');
            Passport passportToFind = passportInfo.Length == 2 ? Passport.CreatePassport(passportInfo[0], passportInfo[1]) : null;

            if (passportToFind != null)
            {
                Passenger searchedPassenger = _passengers.Find(i => i.GetPassport().Number == passportToFind.Number && i.GetPassport().Series == passportToFind.Series);
                Console.WriteLine("What do you want to edit?");

                if (searchedPassenger != null)
                {
                    List <string> editItems = new List <string>()
                    {
                        StringLiterals.FirstName,
                        StringLiterals.LastName,
                        StringLiterals.Nationality,
                        StringLiterals.Passport,
                        StringLiterals.Birthday,
                        StringLiterals.Sex,
                        StringLiterals.Exit
                    };
                    string selectedEditItem = String.Empty;

                    while (selectedEditItem != "Exit")
                    {
                        selectedEditItem = ConsoleManager.DrawMenu(editItems);
                        ConsoleManager.PrepareConsoleForInput();

                        if (selectedEditItem == StringLiterals.FirstName)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newName = Console.ReadLine();

                            searchedPassenger.UpdateFirstName(newName);
                            ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                        }
                        else if (selectedEditItem == StringLiterals.LastName)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newLastName = Console.ReadLine();

                            searchedPassenger.UpdateLastName(newLastName);
                            ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                        }
                        else if (selectedEditItem == StringLiterals.Nationality)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newNationality = Console.ReadLine();

                            searchedPassenger.UpdateNationality(newNationality);
                            ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                        }
                        else if (selectedEditItem == StringLiterals.Passport)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            Console.WriteLine("Passport series;Passport number");
                            string[] pasportInfoToChange = Console.ReadLine().Split(';');
                            if (pasportInfoToChange.Length == 2)
                            {
                                Passport newPassport = Passport.CreatePassport(pasportInfoToChange[0], pasportInfoToChange[1]);
                                if (newPassport != null)
                                {
                                    searchedPassenger.UpdatePassport(newPassport);
                                    ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                                }
                                else
                                {
                                    Console.WriteLine(StringLiterals.IncorrectData);
                                    ConsoleManager.ViewPressEnter();
                                }
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.Birthday)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            Console.WriteLine("Year;Month;Day");
                            string[] birthdayInfo = Console.ReadLine().Split(';');
                            if (birthdayInfo.Length == 3)
                            {
                                DateTime newBirthday = Extensions.CreateDateTime(birthdayInfo[0], birthdayInfo[1], birthdayInfo[2]);

                                searchedPassenger.UpdateBirthday(newBirthday);
                                ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.Sex)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newSex = Console.ReadLine();

                            searchedPassenger.UpdateSex(newSex);
                            ConsoleManager.ViewPassengerWasUpdated(searchedPassenger);
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"Passenger with Passport {passportToFind.Series} - {passportToFind.Number} wasn found");
                    ConsoleManager.ViewPressEnter();
                }
            }
            else
            {
                Console.WriteLine(StringLiterals.IncorrectData);
                ConsoleManager.ViewPressEnter();
            }
        }
Beispiel #2
0
        private void EditFlight()
        {
            ConsoleManager.PrepareConsoleForInput();
            Console.WriteLine("Please enter flight number");
            int numberToSearch = Console.ReadLine().ValidateAndIntParse();

            if (numberToSearch > -1)
            {
                Flight searchedFlight = _flights.FindFlightByFlightNumber(numberToSearch);

                if (searchedFlight != null)
                {
                    Console.WriteLine("What do you want to edit?");
                    List <string> editItems = new List <string>()
                    {
                        StringLiterals.ArrivalCountry,
                        StringLiterals.ArrivalCity,
                        StringLiterals.DepatureCountry,
                        StringLiterals.DepatureCity,
                        StringLiterals.FlightNumber,
                        StringLiterals.Terminal,
                        StringLiterals.Gate,
                        StringLiterals.BuissnesPrice,
                        StringLiterals.EconomyPrice,
                        StringLiterals.CreateAndAddPassenger,
                        StringLiterals.AddExistingPassenger,
                        StringLiterals.DeletePassenger,
                        StringLiterals.Exit
                    };
                    string selectedEditItem = String.Empty;
                    while (selectedEditItem != StringLiterals.Exit)
                    {
                        selectedEditItem = ConsoleManager.DrawMenu(editItems);
                        ConsoleManager.PrepareConsoleForInput();

                        if (selectedEditItem == StringLiterals.ArrivalCountry)
                        {
                            ConsoleManager.PrepareConsoleForInput();
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newArrivalCountry = Console.ReadLine();

                            searchedFlight.UpdateArrivalCountry(newArrivalCountry);
                            ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                        }
                        else if (selectedEditItem == StringLiterals.ArrivalCity)
                        {
                            ConsoleManager.PrepareConsoleForInput();
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newArrivalCity = Console.ReadLine();

                            searchedFlight.UpdateArrivalCity(newArrivalCity);
                            ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                        }
                        else if (selectedEditItem == StringLiterals.DepatureCountry)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newDepatureCountry = Console.ReadLine();

                            searchedFlight.UpdateDepatureCountry(newDepatureCountry);
                            ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                        }
                        else if (selectedEditItem == StringLiterals.DepatureCity)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            string newDepatureCity = Console.ReadLine();

                            searchedFlight.UpdateDepatureCity(newDepatureCity);
                            ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                        }
                        else if (selectedEditItem == StringLiterals.FlightNumber)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            int newFlightNum = Console.ReadLine().ValidateAndIntParse();
                            if (newFlightNum > -1)
                            {
                                searchedFlight.UpdateFlightNumber(newFlightNum);
                                ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.Terminal)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            int newTerminal = Console.ReadLine().ValidateAndIntParse();

                            if (newTerminal > -1)
                            {
                                searchedFlight.UpdateTerminal(newTerminal);
                                ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.Gate)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            int newGate = Console.ReadLine().ValidateAndIntParse();

                            if (newGate > -1)
                            {
                                searchedFlight.UpdateGate(newGate);
                                ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.BuissnesPrice)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            int newBuissnessPrice = Console.ReadLine().ValidateAndIntParse();

                            if (newBuissnessPrice > -1)
                            {
                                searchedFlight.UpdateBuissnesPrice(newBuissnessPrice);
                                ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.EconomyPrice)
                        {
                            Console.WriteLine($"Please Enter new {selectedEditItem}");
                            int newEconomyPrice = Console.ReadLine().ValidateAndIntParse();

                            if (newEconomyPrice > -1)
                            {
                                searchedFlight.UpdateEconomyPrice(newEconomyPrice);
                                ConsoleManager.ViewFlightWasUpdated(searchedFlight);
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                                ConsoleManager.ViewPressEnter();
                            }
                        }
                        else if (selectedEditItem == StringLiterals.CreateAndAddPassenger)
                        {
                            Console.WriteLine("Please Enter data to create a passenger:");
                            Console.WriteLine("First Name;Last Name");
                            string[] nameLastName = Console.ReadLine().Split(';');
                            Console.WriteLine("Nationality;Sex");
                            string[] nationalitySex = Console.ReadLine().Split(';');
                            Console.WriteLine("Passport series;passport Number");
                            string[] passportInfo = Console.ReadLine().Split(';');
                            Console.WriteLine("Year;month;day");
                            string[] birthday = Console.ReadLine().Split(';');

                            if (nameLastName.Length == 2 && nationalitySex.Length == 2 && passportInfo.Length == 2 && birthday.Length == 3)
                            {
                                Passenger passenger = Passenger.CreatePassenger(nameLastName[0], nameLastName[1], nationalitySex[0], Passport.CreatePassport(passportInfo[0], passportInfo[1]), Extensions.CreateDateTime(birthday[0], birthday[1], birthday[2]), nationalitySex[1]);
                                if (passenger != null)
                                {
                                    searchedFlight.AddPassenger(passenger, new Ticket(TicketClass.Economy, searchedFlight.GetFlightNumber(), searchedFlight.GetPrice().EcomonyPrice));
                                    _passengers.Add(passenger);
                                    ConsoleManager.ViewPassengerInfo(passenger);
                                    Console.WriteLine($"Passenger was created and added to flight :{searchedFlight.GetFlightNumber()}");
                                }
                                else
                                {
                                    Console.WriteLine(StringLiterals.IncorrectData);
                                }
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                            }

                            ConsoleManager.ViewPressEnter();
                        }
                        else if (selectedEditItem == StringLiterals.AddExistingPassenger)
                        {
                            Console.WriteLine("Please Enter Passport series;Passport number to find a passenger");
                            string[] passportInfo   = Console.ReadLine().Split(';');
                            Passport passportToFind = passportInfo.Length == 2 ? Passport.CreatePassport(passportInfo[0], passportInfo[1]) : null;
                            if (passportToFind != null)
                            {
                                Passenger passenger = _passengers.Find(i => i.GetPassport().Number == passportToFind.Number && i.GetPassport().Series == passportToFind.Series);

                                if (passenger != null)
                                {
                                    bool added = searchedFlight.AddPassenger(passenger, new Ticket(TicketClass.Economy, searchedFlight.GetFlightNumber(), searchedFlight.GetPrice().EcomonyPrice));

                                    if (_passengers.Contains(passenger))
                                    {
                                        _passengers.Add(passenger);
                                    }
                                    if (added)
                                    {
                                        ConsoleManager.ViewPassengerInfo(passenger);
                                        Console.WriteLine($"Passenger was added to flight:{searchedFlight.GetFlightNumber()}");
                                    }
                                    else
                                    {
                                        Console.WriteLine("Passenger is already exist in te flight passengers");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Passenger wasnt found");
                                }
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                            }
                            ConsoleManager.ViewPressEnter();
                        }
                        else if (selectedEditItem == StringLiterals.DeletePassenger)
                        {
                            Console.WriteLine("Please Enter Passport series;Passport number to find a passenger");
                            string[] passportInfo   = Console.ReadLine().Split(';');
                            Passport passportToFind = passportInfo.Length == 2 ? Passport.CreatePassport(passportInfo[0], passportInfo[1]) : null;
                            if (passportToFind != null)
                            {
                                Passenger passenger = _passengers.Find(i => i.GetPassport().Number == passportToFind.Number && i.GetPassport().Series == passportToFind.Series);
                                bool      removed   = _flights.FindFlightByFlightNumber(searchedFlight.GetFlightNumber()).DeletePassenger(passenger);

                                if (removed == true)
                                {
                                    ConsoleManager.ViewPassengerInfo(passenger);
                                    Console.WriteLine($"Passenger was removed to flight:{searchedFlight.GetFlightNumber()}");
                                }
                                else
                                {
                                    Console.WriteLine("Passenger is not exist");
                                }
                            }
                            else
                            {
                                Console.WriteLine(StringLiterals.IncorrectData);
                            }
                            ConsoleManager.ViewPressEnter();
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"The Flight with current Flight Number {numberToSearch} wasnt found");
                }
            }
            else
            {
                Console.WriteLine(StringLiterals.IncorrectData);
                ConsoleManager.ViewPressEnter();
            }
        }