static void Main(string[] args) { Console.WriteLine("Welcome to Address Book Problem\nChoose one of the option"); bool loop1 = true; while (loop1) { Console.WriteLine("\n1.Add AddressBook \n2.View AddressBooks"); Console.WriteLine("3.Searching Contact by City or State\n4.Add AdrdressBook to the IO File\n5.Read AdrdressBook from the IO File "); Console.WriteLine("6.Add AdrdressBook to the CSV File\n7.Read AdrdressBook from CSV file\n8.Add AdrdressBook to the Json File\n9.Read AdrdressBook from Json file\n0.Exit "); int choice1 = 0; try { choice1 = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("Invalid Input!! Try again"); } AddressBook addressBook = new AddressBook(); string addressBookName = null; switch (choice1) { case 1: Console.WriteLine("\nAdding a new AddessBook"); Console.WriteLine("Enter name for New AddessBook:"); addressBookName = Console.ReadLine(); bool isKeyAvailable = false; foreach (KeyValuePair <string, AddressBook> keyValue in addressBookDictionary) { if (keyValue.Key.Equals(addressBookName)) { isKeyAvailable = true; } } if (isKeyAvailable) { Console.WriteLine("AddessBook Name is available, try other name\n"); break; } bool loop2 = true; while (loop2) { Console.WriteLine("\n1.Add a Contact \n2.View Contact By Name \n3.View All Contacts \n4.Edit Contact By name"); Console.WriteLine("5.Delete Contact By Name \n6.Exit "); int choice = 0; try { choice = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("Invalid Input!! Try again"); } switch (choice) { case 1: Console.WriteLine("\nAdding a new Contact\n"); addressBook.AddContact(); break; case 2: addressBook.ViewContact(); break; case 3: addressBook.ViewAllContacts(); break; case 4: addressBook.EditContact(); break; case 5: addressBook.DeleteContact(); break; default: loop2 = false; break; } Console.WriteLine("______________________________________________________"); } addressBookDictionary.Add(addressBookName, addressBook); addressBooksList.Add(addressBook); break; case 2: Console.WriteLine("Available AddressBooks: "); foreach (KeyValuePair <String, AddressBook> keyValue in addressBookDictionary) { Console.WriteLine("AddressBook Name: " + keyValue.Key); } break; case 3: Console.WriteLine("Your Searching Contact by City or State"); AddressBookMain.ContactsByCityOrState(); break; case 4: Console.WriteLine("Adding AddressBook into IO File"); AddressBookMain.AddAddressBookToFileIO(); break; case 5: Console.WriteLine("Read AddressBook from IO File"); AddressBookMain.ReadAddressBookToFileIO(); break; case 6: Console.WriteLine("Adding AddressBook into CSV File"); AddressBookMain.AddAddressBookToCsv(); break; case 7: Console.WriteLine("Reading AddressBook from CSV File"); AddressBookMain.ReadAddressBookFromCsv(); break; case 8: Console.WriteLine("Adding AddressBook into Json File"); AddressBookMain.AddAddressBookToJsonFile(); break; case 9: Console.WriteLine("Reading AddressBook from Json File"); AddressBookMain.ReadAddressBookFromJsonFile(); break; default: loop1 = false; break; } Console.WriteLine("______________________________________________________"); } Console.WriteLine("Thanks for Using the Application!!"); }
static void Main(string[] args) { Console.WriteLine("Welcome to Address Book Problem\nChoose one of the option"); //Constants: const int ADD_ADDRESSBOOK = 1; const int ADD_CONTACT = 1; const int EDIT_CONTACT = 2; const int DELETE_CONTACT = 3; //variables bool b1 = true; while (b1) { Console.WriteLine("\n1.Add AddressBook\n2.Exit\n"); int choose1 = Convert.ToInt32(Console.ReadLine()); switch (choose1) { case ADD_ADDRESSBOOK: AddressBook ad = new AddressBook(); bool b = true; while (b) { Console.WriteLine("\n1.Add contacts\n2.Edit Contact using name\n3.Delete Contact using name\n4.Exit"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case ADD_CONTACT: Console.WriteLine("\nAdding a new Contact\n"); ad.AddContact(); break; case EDIT_CONTACT: Console.WriteLine("Edit Contact Using name\n"); Console.WriteLine("Enter First Name: "); String fname = Console.ReadLine(); Console.WriteLine("Enter last Name: "); String lname = Console.ReadLine(); bool isEdited = ad.EditContact(fname, lname); if (isEdited) { Console.WriteLine("\nDetails Updated SuccessFully!!\n"); } else { Console.WriteLine("\nNo contact exits with this name\nEdite failed!!\n"); } break; case DELETE_CONTACT: Console.WriteLine("Delete Contact Using name\n"); Console.WriteLine("Enter First Name: "); String fName = Console.ReadLine(); Console.WriteLine("Enter last Name: "); String lName = Console.ReadLine(); bool isDeleted = ad.DeleteContact(fName, lName); if (isDeleted) { Console.WriteLine("\nContact SuccessFully!!\n"); } else { Console.WriteLine("\nNo contact exits with this name\nDelete failed!!\n"); } break; default: b = false; break; } } break; default: b1 = false; break; } Console.Out.WriteLine("*******************************************\n"); } }