/// <summary> /// UC 8 : SEARCHES FOR THE PERSON IN A PARTICULAR STATE OR CITY ACROSS ALL ADDRESS BOOKS AND DISPLAYS THE DETAILS /// </summary> public void SearchPersonByCityOrState() { AddressBookMain addressBook = new AddressBookMain(); Console.WriteLine("Enter either a city or state name below to search for people:"); string cityOrStateName = Console.ReadLine().ToUpper(); Console.WriteLine("Enter first name of the person you are searching"); string firstName = Console.ReadLine().ToUpper(); Console.WriteLine("Enter last name"); string lastName = Console.ReadLine().ToUpper(); if (addressBookListDictionary.Count != 0) { bool flag = false; foreach (var kvp in addressBookListDictionary) { for (int i = 0; i < kvp.Value.contactList.Count; i++) { if (kvp.Value.contactList[i].city == cityOrStateName || kvp.Value.contactList[i].state == cityOrStateName) { if (kvp.Value.contactList[i].firstName == firstName && kvp.Value.contactList[i].lastName == lastName) { /// IF BOTH NAME AND CITY/STATE OF A CONTACT ACROSS ANY ADDRESS BOOK MATCHES THE ENTERED DETAILS Console.WriteLine("\nContact found inside address book: " + kvp.Key); Console.WriteLine("FullName: " + kvp.Value.contactList[i].firstName + " " + kvp.Value.contactList[i].lastName + "\nAddress: " + kvp.Value.contactList[i].address + "\nCity: " + kvp.Value.contactList[i].city + "\nState: " + kvp.Value.contactList[i].state + "\nZip: " + kvp.Value.contactList[i].zip + "\nPhoneNumber: " + kvp.Value.contactList[i].phoneNumber + "\nEmail: " + kvp.Value.contactList[i].email + "\n"); flag = true; break; } } } } /// IF flag VALUE DOES NOT CHANGE MEANS NO MATCH FOR THE ENTERED DETAILS WAS FOUND if (flag == false) { Console.WriteLine("\nNo such contact found"); } } else { Console.WriteLine("\nNo stored address book found, please add one"); } }
/// <summary> /// UC 6 : ADDS A NEW ADDRESS BOOK WITH UNIQUE NAME TO THE SYSTEM /// </summary> public void AddNewAddressBook() { Console.WriteLine("Enter the name of address book:"); string addressBookName = Console.ReadLine().ToUpper(); AddressBookMain addressBook = new AddressBookMain(addressBookName); /// HANDLES THE EXCEPTION WHEN THE USER TRIES TO ENTER DUPLICATE ADDRESS BOOK NAME try { addressBookListDictionary.Add(addressBookName, addressBook); Console.WriteLine("\nAddress Book " + addressBookName + " added successfully"); Console.WriteLine("Updated Address Book List:"); foreach (var kvp in addressBookListDictionary) { Console.WriteLine(kvp.Key); } } catch (Exception) { Console.WriteLine("Address Book {0} already exists, please access it or add a new address book with different name!", addressBookName); } }
public static void MainMenuOperation() { AddressBookList addressBookList = new AddressBookList(); bool flag1 = true; while (flag1) { string currentAddressBookName = ""; Console.WriteLine("\nEnter:\n1-To add a new address Book\n2-To access an existing address book" + "\n3-To search person in a state or city across multiple address books\n4-View all persons of a city or state" + "\n5-To get count of contacts present at a city or state\n6-To exit"); int options1 = Convert.ToInt32(Console.ReadLine()); switch (options1) { case 1: addressBookList.AddNewAddressBook(); break; case 2: currentAddressBookName = addressBookList.ExistingAddressBook(); break; case 3: addressBookList.SearchPersonByCityOrState(); break; case 4: AddressBookMain.ViewPeopleByCityOrState(); break; case 5: AddressBookMain.GetCountByCityOrState(); break; case 6: flag1 = false; break; } if (currentAddressBookName != "") { bool flag2 = true; while (flag2) { Console.WriteLine("\nCurrent address book:" + currentAddressBookName); Console.WriteLine("Enter:\n1-To add a new contact\n2-To edit an existing contact\n3-To search for an existing contact\n4-To delete a contact\n5-To display all contacts in the address book\n6-To return to main menu"); int options2 = Convert.ToInt32(Console.ReadLine()); switch (options2) { case 1: addressBookList.addressBookListDictionary[currentAddressBookName].AddNewContact(); break; case 2: addressBookList.addressBookListDictionary[currentAddressBookName].EditContact(); break; case 3: addressBookList.addressBookListDictionary[currentAddressBookName].SearchContactByName(); break; case 4: addressBookList.addressBookListDictionary[currentAddressBookName].DeleteContact(); break; case 5: addressBookList.addressBookListDictionary[currentAddressBookName].ViewAllContacts(); break; case 6: flag2 = false; break; } } } } }