Beispiel #1
0
        public void Process(PhoneBookOperation operation)
        {
            switch (operation)
            {
            case PhoneBookOperation.AddContact:
                AddContact();
                break;

            case PhoneBookOperation.EditContact:
                EditContact();
                break;

            case PhoneBookOperation.DisplayAllContacts:
                DisplayAllContacts();
                break;

            case PhoneBookOperation.RemoveContact:
                RemoveContact();
                break;

            case PhoneBookOperation.SearchName:
                SearchName();
                break;

            case PhoneBookOperation.SearchPhoneNumber:
                SearchPhoneNumber();
                break;

            case PhoneBookOperation.DisplayContact:
                DisplayContact();
                break;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var phoneBookOperator = new PhoneBookOperator();

            Console.WriteLine("Welcome to console phone book");
            Console.WriteLine("Type in 'bye' to exit");


            string userInput = "";

            do
            {
                Console.WriteLine();
                Console.WriteLine("*************");
                Console.WriteLine("Options:");
                Console.WriteLine("1: Add contact");
                Console.WriteLine("2: Remove contact");
                Console.WriteLine("3: Edit contact");
                Console.WriteLine("4: Display All Contacts");
                Console.WriteLine("5: Search honeNumber");
                Console.WriteLine("6: Search Name");
                Console.WriteLine("7: Display contact");
                Console.WriteLine("Insert your option or type 'bye' to exit:");

                userInput = Console.ReadLine();
                if (userInput == "bye")
                {
                    return;
                }

                object input;



                if (Enum.TryParse(typeof(PhoneBookOperation), userInput, true, out input))
                {
                    PhoneBookOperation operation = (PhoneBookOperation)input;
                    phoneBookOperator.Process(operation);
                }
                else
                {
                    Console.WriteLine("Invalid input, try again");
                }
                Console.WriteLine("*************");
                Console.WriteLine();
            } while (true);
        }