Esempio n. 1
0
        private static NationalPark GetParkByLocationNumber(string locNumber)
        {
            NationalPark park = null;

            if (!string.IsNullOrWhiteSpace(locNumber))
            {
                park = _parks.Where(x => !string.IsNullOrWhiteSpace(x.LocationNumber) &&
                                    x.LocationNumber.Equals(locNumber, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            }
            return(park);
        }
Esempio n. 2
0
        private static bool EditPark(NationalPark parkToEdit)
        {
            Console.WriteLine();
            Console.WriteLine("Which field would you like to edit?");
            Console.WriteLine("1. Press 1 to edit park name");
            Console.WriteLine("2. Press 2 to edit park state");
            Console.WriteLine("3. Press 3 to return to edit menu");
            Console.WriteLine("4. Press 4 to return to main menu");
            var userChoice = Console.ReadKey();

            Console.WriteLine();
            var returnToMainWithoutPrompt = false;

            switch (userChoice.KeyChar)
            {
            case ('1'):
                Console.WriteLine($"Current park name: {parkToEdit.LocationName}");
                Console.WriteLine("Enter new park name:");
                var newParkName = Console.ReadLine();
                var oldName     = parkToEdit.LocationName;
                parkToEdit.LocationName = newParkName;
                WriteParksToFile();
                Console.WriteLine($"You successfully renamed '{oldName}' to '{newParkName}'.");
                break;

            case ('2'):
                Console.WriteLine($"Current park state: {parkToEdit.State}");
                Console.WriteLine("Enter new park state:");
                var newParkState = Console.ReadLine();
                var oldState     = parkToEdit.State;
                parkToEdit.State = newParkState;
                WriteParksToFile();
                Console.WriteLine($"You successfully changed the park state from '{oldState}' to '{newParkState}'.");
                break;

            case ('3'):
                Console.Clear();
                LoadEditParkMenu();
                break;

            case ('4'):
                // valid option, return control to main menu below
                returnToMainWithoutPrompt = true;
                break;

            default:
                ShowInvalidUserInputMessage(userChoice.KeyChar.ToString());
                break;
            }

            return(returnToMainWithoutPrompt);
        }
Esempio n. 3
0
        private static void AddNewPark()
        {
            Console.WriteLine(" Enter new Park State Abbreviation: ");
            var state = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(state))
            {
                Console.WriteLine("Invalid state name. Hit ENTER to return to Main Menu.");
                Console.ReadLine();
                return;
            }

            Console.WriteLine();

            Console.WriteLine(" Enter new Park Name: ");
            var parkName = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(parkName))
            {
                Console.WriteLine("Invalid park name.Hit ENTER to return to Main Menu.");
                Console.ReadLine();
                return;
            }

            Console.WriteLine();

            Console.WriteLine(" Enter new Park Location Number: ");
            var locNumber = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(locNumber))
            {
                Console.WriteLine("Invalid park location number.Hit ENTER to return to Main Menu.");
                Console.ReadLine();
                return;
            }

            var newPark = new NationalPark();

            newPark.State          = state;
            newPark.LocationName   = parkName;
            newPark.LocationNumber = locNumber;

            _parks.Add(newPark);

            WriteParksToFile();

            Console.WriteLine($"You successfully added a new park: '{newPark}'");
            Console.WriteLine("Hit ENTER to return to main menu");
            Console.ReadLine();
        }