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; } } }
public void AddAddressBook() { try { AddressBook addressBook = GetAddressBook(); //get the name of the addressbook if (addressBook == null) //address book is empty { Console.WriteLine("Address Book Empty"); return; } while (true) { Console.WriteLine($"\n**** Welcome To {addressBook.nameOfAddressBook} Address Book System ****"); Console.Write("\n1.Add New contact" + "\n2.Display all contacts" + "\n3.Edit Record" + "\n4.Delete Records" + "\n5.Search Contact Records" + "\n6.Write Address Book System to txt File" + "\n7.Write Address Book System to CSV File" + "\n8.Write Address Book System to JSON File" + "\n9.Read Txt File" + "\n10.Read CSV File " + "\n11.Read JSON File " + "\n0.Exit\n " + "\nEnter Your Choice:- "); int choice4 = Convert.ToInt32(Console.ReadLine()); switch (choice4) { case 1: addressBook.AddContact(); break; case 2: addressBook.GetAllContacts(); break; case 3: addressBook.EditContact(); break; case 4: addressBook.RemoveContact(); break; case 5: addressBook.SearchContactDetails(); break; case 6: addressBook.WriteAddressBookToFile(); break; case 7: addressBook.WriteAddressBookToCsv(); break; case 8: addressBook.WriteAddressBookToJson(); break; case 9: addressBook.ReadAddressBookFromFile(); break; case 10: addressBook.ReadAddressBookFromCSV(); break; case 11: addressBook.ReadAddressBookFromJSON(); break; case 0: Console.WriteLine("Exiting Address Book"); return; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }