コード例 #1
0
        public void AddOrAccessAddressBook()
        {
            // To get the name of the addressbook
            AddressBook addressBook = GetAddressBook();

            // Returns no record found if address book is empty
            if (addressBook == null)
            {
                Console.WriteLine("Action aborted");
                return;
            }
            //select the action to be performed in address book
            while (true)
            {
                Console.WriteLine("\nSelect from below to work on Address book {0}", addressBook.nameOfAddressBook);
                Console.WriteLine("\nType\n\nAdd - To add a contact \nUpdate- To update a contact\nView - To view all contacts\nRemove - To remove a contact and \nSearch- To search to get contact deatails\nE - To exit\n ");

                switch (Console.ReadLine().ToLower())
                {
                case ADD_CONTACT:

                    addressBook.AddContact();
                    break;

                case UPDATE_CONTACT:

                    addressBook.UpdateContact();
                    break;

                case SEARCH_CONTACT:

                    addressBook.DisplayContactDetails();
                    break;

                case REMOVE_CONTACT:

                    addressBook.RemoveContact();
                    break;

                case GET_ALL_CONTACTS:

                    addressBook.GetAllContacts();
                    break;

                default:

                    Console.WriteLine("\nInvalid option. Exiting address book");
                    return;
                }
                // Ask the user to continue in same address book or to exit
                Console.WriteLine("\nType y to continue in same address Book or any other key to exit");
                // If not equal to y  then exit
                if (!(Console.ReadLine().ToLower() == "y"))
                {
                    logger.Debug("User exited the address book " + nameOfAddressBook);
                    return;
                }
            }
        }