static void Main(string[] args) { Console.WriteLine("Welcome to Address Book Program ..!\n"); AddressBookManager addressBookManager = new AddressBookManager(); addressBookManager.startAddressBook(); }
static void Main(string[] args) { addressBookManager = new AddressBookManager(); addressBooks = addressBookManager.addressBooks; cityContactMap = addressBookManager.cityContactMap; stateContactMap = addressBookManager.stateContactMap; Console.WriteLine("Welcome to Address Book System!"); var quit = false; while (!quit) { Console.Write("Choose an option\n1.Create New Address Book\n2.Open an address book\n3.View Persons by City\n4.View Persons by state" + "\n5.Search a person in a city\n6.Search a person in a state" + "\n7.Quit\nEnter Your Option :"); var input = Convert.ToInt32(Console.ReadLine()); switch (input) { case 1: Console.Write("Enter a name for your address book :"); var name = Console.ReadLine(); addressBooks.Add(name, new AddressBook()); InitializeAddressBook(name); break; case 2: Console.Write("Enter name of the address book to open :"); name = Console.ReadLine(); if (!addressBooks.ContainsKey(name)) { Console.WriteLine("No Such Address Book Exists!"); } else { InitializeAddressBook(name); } break; case 3: Console.Write("Enter the city : "); var city = Console.ReadLine(); if (!addressBookManager.cityContactMap.ContainsKey(city)) { Console.WriteLine("No Such City Exists"); } else { Console.WriteLine("Found {0} Results : ", addressBookManager.cityContactMap[city].Count); int i = 1; foreach (var item in addressBookManager.cityContactMap[city]) { Console.WriteLine("{0}. {1}", i++, item.firstName); } ; } break; case 4: Console.Write("Enter the state :"); var state = Console.ReadLine(); if (!addressBookManager.stateContactMap.ContainsKey(state)) { Console.WriteLine("No Such State Exists"); } else { Console.WriteLine("Found {0} Results : ", addressBookManager.stateContactMap[state].Count); int i = 1; foreach (var item in addressBookManager.stateContactMap[state]) { Console.WriteLine("{0}. {1}", i++, item.firstName); } ; } break; case 5: Console.Write("Enter City to Search in : "); var searchCity = Console.ReadLine(); Console.Write("Enter name to search : "); var searchName = Console.ReadLine(); var list = addressBookManager.SearchInCity(searchName, searchCity); if (list == null) { Console.WriteLine("No Such City in Address Books."); } else { Console.WriteLine("Found {0} persons named {1} in {2}", list.Count, searchName, searchCity); } break; case 6: Console.Write("Enter State to Search in : "); var searchState = Console.ReadLine(); Console.Write("Enter name to search : "); searchName = Console.ReadLine(); list = addressBookManager.SearchInState(searchName, searchState); if (list == null) { Console.WriteLine("No Such State in Address Books."); } else { Console.WriteLine("Found {0} persons named {1} in {2}", list.Count, searchName, searchState); } break; case 7: quit = true; break; default: Console.WriteLine("Invalid Input"); break; } } }