static void Main(string[] args) { Console.WriteLine("Wellcome To Address Book System Program!"); Console.WriteLine("*****************************************"); int choice = 0; while (choice != 4) { Console.WriteLine("1.Add Contacts"); Console.WriteLine("2.Edit Existing Contact"); Console.WriteLine("3.Delete Person Details"); Console.WriteLine("5.Search persons using city or state"); Console.WriteLine("6.Search Number of persons in city or state"); Console.WriteLine("7.Enter name of the address book you want to record in sorting order"); Console.WriteLine("8.To ordered the record by city or state or zip Please enter book name"); Console.WriteLine("9.To Read Data from file"); Console.WriteLine("10.To Append Data into file"); Console.WriteLine("11.To Read Data from CSV file"); Console.WriteLine("12.To Read Data JSON file"); Console.WriteLine("13.To Write Data in JSON file"); Console.WriteLine("4.close"); choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("Enter name of the address book in which you want to add record."); String bookName = Console.ReadLine(); AddressBook.addBook(bookName); break; case 2: Console.WriteLine("Enter the book name in which you want to Edit data:"); string bookNameHasReocrd = Console.ReadLine(); Console.WriteLine("Enter Person's FirstName to edit data:"); string recordNameToEdit = Console.ReadLine(); AddressBook.edit(bookNameHasReocrd, recordNameToEdit); break; case 3: Console.WriteLine("Enter name of the address book you want to delete record in."); String bookName1 = Console.ReadLine(); AddressBook.delete(bookName1); break; case 4: choice = 4; break; case 5: Console.WriteLine("Enter city or state to find a person"); string cityOrState = Console.ReadLine(); AddressBook.searchPersonUsingCityOrStateInMultipleBooks(cityOrState); break; case 6: Console.WriteLine("Enter city or state to get total number of persons"); string cityOrState1 = Console.ReadLine(); int numberOfPerson = AddressBook.searchNumberOfPersonUsingCityOrStateInMultipleBooks(cityOrState1); Console.WriteLine("Total number of persons are :" + numberOfPerson); break; case 7: Console.WriteLine("Enter name of the address book you want to record in sorting order"); String bookName2 = Console.ReadLine(); AddressBook.PrintNameInAlphabeticalOrder(bookName2); break; case 8: Console.WriteLine("8.To ordered the record by city or state or zip Please enter any one city,state or zip"); String cityOrStateOrZip = Console.ReadLine(); Console.WriteLine("Enter bookName"); string bookName3 = Console.ReadLine(); AddressBook.sortEntriesInAlphabeticalOrderUsingCityStateOrZip(cityOrStateOrZip, bookName3); break; case 9: FileOperation.ReadFromStreamReader(); break; case 10: FileOperation.WriteUsingStreamWriter(); break; case 11: FileOperation.ReadFromCSVReader(); break; case 12: FileOperation.ReadFromJSONFile(); break; case 13: FileOperation.WriteIntoJSONFile(); break; default: Console.WriteLine("Invalid choice !"); break; } } }
static void Main(string[] args) { Console.WriteLine("Welcome to Address Book Program."); AddressBook addressBook = new AddressBook(); int choice, choice2; string bookName = "default"; Console.WriteLine("Would You Like To \n1.Work on default AddressBook \n2.Create New AddressBook"); choice2 = Convert.ToInt32(Console.ReadLine()); switch (choice2) { case 1: addressBook.AddAddressBook(bookName); break; case 2: Console.WriteLine("Enter Name Of New Addressbook You want to create : "); bookName = Console.ReadLine(); addressBook.AddAddressBook(bookName); break; default: Console.WriteLine("Invalid Input, Proceeding with default AddressBook"); addressBook.AddAddressBook(bookName); break; } do { Console.WriteLine($"Working On {bookName} AddressBook\n"); Console.WriteLine("Choose An Option \n1.Add New Contact \n2.Edit Existing Contact \n3.Delete A Contact \n4.View A Contact \n5.View All Contacts \n6.Exit Application\n"); choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("Enter First Name :"); string firstName = Console.ReadLine(); Console.WriteLine("Enter Last Name :"); string lastName = Console.ReadLine(); Contact temp = new Contact() { FirstName = firstName, LastName = lastName }; if (addressBook.CheckDuplicateEntry(temp, bookName)) { break; } Console.WriteLine("Enter Address :"); string address = Console.ReadLine(); Console.WriteLine("Enter City :"); string city = Console.ReadLine(); Console.WriteLine("Enter State :"); string state = Console.ReadLine(); Console.WriteLine("Enter Email :"); string email = Console.ReadLine(); Console.WriteLine("Enter Zip :"); int zip = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Phone Number :"); long phoneNumber = Convert.ToInt64(Console.ReadLine()); addressBook.AddContact(firstName, lastName, address, city, state, email, zip, phoneNumber, bookName); break; case 2: Console.WriteLine("Enter First Name Of Contact To Edit :"); string nameToEdit = Console.ReadLine(); addressBook.EditContact(nameToEdit, bookName); break; case 3: Console.WriteLine("Enter First Name Of Contact To Delete :"); string nameToDelete = Console.ReadLine(); addressBook.DeleteContact(nameToDelete, bookName); break; case 4: Console.WriteLine("Enter First Name Of Contact To View :"); string nameToView = Console.ReadLine(); addressBook.ViewContact(nameToView, bookName); break; case 5: addressBook.ViewContact(bookName); break; case 6: Console.WriteLine("Enter Name For New AddressBook"); string newAddressBook = Console.ReadLine(); addressBook.AddAddressBook(newAddressBook); Console.WriteLine("Would you like to Switch to " + newAddressBook); Console.WriteLine("1.Yes \n2.No"); int c = Convert.ToInt32(Console.ReadLine()); if (c == 1) { bookName = newAddressBook; } break; case 7: Console.WriteLine("Enter Name Of AddressBook From Below List"); foreach (KeyValuePair <string, AddressBook> item in addressBook.GetAddressBook()) { Console.WriteLine(item.Key); } while (true) { bookName = Console.ReadLine(); if (addressBook.GetAddressBook().ContainsKey(bookName)) { break; } else { Console.WriteLine("No such AddressBook found. Try Again."); } } break; case 8: Console.WriteLine("Would You Like To \n1.Search by city \n2.Search by state"); int opt = Convert.ToInt32(Console.ReadLine()); switch (opt) { case 1: Console.WriteLine("Enter name of city :"); addressBook.SearchPersonByCity(Console.ReadLine()); break; case 2: Console.WriteLine("Enter name of state :"); addressBook.SearchPersonByState(Console.ReadLine()); break; default: Console.WriteLine("Invalid Input.Enter 1 or 2"); break; } break; case 9: addressBook.DisplayCountByCityandState(); break; case 10: Console.WriteLine("\n1.Sort By Name \n2.Sort By City \n3.Sort By State \n4.Sort By Zip"); int ch = Convert.ToInt32(Console.ReadLine()); switch (ch) { case 1: addressBook.SortByName(); break; case 2: addressBook.SortByCity(); break; case 3: addressBook.SortByState(); break; case 4: addressBook.SortByZip(); break; default: Console.WriteLine("Invalid Choice"); break; } break; case 11: FileOperation fileIO = new FileOperation(); fileIO.WriteToFile(addressBook.addressBookDictionary); fileIO.ReadFromFile(); break; case 12: CSVHandler handler = new CSVHandler(); handler.WriteToFile(addressBook.addressBookDictionary); handler.ReadFromFile(); break; case 13: JsonOperation json = new JsonOperation(); json.WriteToFile(addressBook.addressBookDictionary); json.ReadFromFile(); break; case 0: Console.WriteLine("Thank You For Using Address Book System."); break; default: Console.WriteLine("Invalid Entry. Enter value between 0 to 7"); break; } } while (choice != 0); }