Ejemplo n.º 1
0
        private static void Execute()
        {
            int contactId;

            do
            {
                Console.Clear();
                ConsoleLogging.WhichActionText();
                var userChoice = Console.ReadKey();
                Console.WriteLine();
                switch (userChoice.Key)
                {
                case ConsoleKey.D1:
                case ConsoleKey.NumPad1:
                    Console.Clear();
                    PhoneBook.CreateContact(PhoneBook.ContactList.Count);
                    ConsoleLogging.PressEnter();
                    break;

                case ConsoleKey.D2:
                case ConsoleKey.NumPad2:
                    Console.Clear();
                    PhoneBook.GetAllContacts();
                    ConsoleLogging.PressEnter();
                    break;

                case ConsoleKey.D3:
                case ConsoleKey.NumPad3:
                    Console.Clear();
                    contactId = ConsoleLogging.GetContactToUpdate();
                    PhoneBook.UpdateContact(contactId);
                    ConsoleLogging.PressEnter();
                    break;

                case ConsoleKey.D4:
                case ConsoleKey.NumPad4:
                    Console.Clear();
                    contactId = ConsoleLogging.GetContactToDelete();
                    PhoneBook.DeleteContact(contactId);
                    ConsoleLogging.PressEnter();
                    break;

                case ConsoleKey.D5:
                case ConsoleKey.NumPad5:
                    Console.Clear();
                    FileMaster.WriteFile(PhoneBook.ContactList);
                    Console.WriteLine("Thank You!");
                    Environment.Exit(0);
                    break;
                }
            } while (true);
        }
        internal static int GetContactToUpdate()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Which contact do you want to update? Please select based on the id. Press 0 if you " +
                              "want to go back to the main menu.");
            Console.WriteLine();
            Console.ResetColor();
            PhoneBook.GetAllContacts();

            int id;

            id = GetIdSafely();

            return(id);
        }