public void RemoveContact() { try { if (contactList.Count() == 0) // If the List does not have any contacts { Console.WriteLine("Record Not Found"); return; } Console.Write("Enter Name of contact to be Removed:- "); string name = Console.ReadLine(); ContactDetails contact = SearchByName(name); // Search for the contact if (contact == null) // If contact doesnt exist { Console.WriteLine("No record found"); return; } contact.Display();// Print the details of contact contactList.Remove(contact); AddressBookDetails.cityToContactMap[contact.City].Remove(contact); //remove city from Dictionary AddressBookDetails.stateToContactMap[contact.State].Remove(contact); //remove State from Dictionary Console.WriteLine("Successfully Record Deleted"); //print } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void SearchContactDetails() //create Search record method { try { if (contactList.Count() == 0) //List doesnt have any contacts { Console.WriteLine("No Record Found"); //print msg return; } Console.WriteLine("\nEnter the name of candidate to get Details"); string name = Console.ReadLine().ToLower(); ContactDetails contact = SearchByName(name); // Search the contact by name if (contact == null) // If contact doesnt exist { Console.WriteLine("No record found"); return; } contact.Display();// Print the details of the contact after search } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void EditContact() //Create EditContact method to edite record { try { if (contactList.Count() == 0) //List have no contacts { Console.WriteLine(" Record Not Found"); //print return; } Console.Write("Enter First Name :- "); //Take First Name string name = Console.ReadLine(); ContactDetails contact = SearchByName(name); // Search the name if (contact == null) // If contact doesnt exist { Console.WriteLine($"{name } Record Not Found"); //Print return; } contact.Display(); // print record of searched contact int updateAttributeNum = 0; Console.Write("Enter Row number Record to be Edit:- "); //print and take input try { updateAttributeNum = Convert.ToInt32(Console.ReadLine()); if (updateAttributeNum == 0) { return; } } catch { Console.WriteLine("Invalid entry"); return; } Console.Write("Enter the New Record:- "); // Take input string newValue = Console.ReadLine(); switch (updateAttributeNum) // Updating selected attribute with selected value { case UPDATE_FIRST_NAME: firstName = contact.FirstName; // Store the firstname of contact in variable contact.FirstName = newValue; // Update the contact with given name if (contact.Equals(contactList)) // If duplicate contact exists with that name then revert the operation { contact.FirstName = firstName; Console.Write($"Contact already exists that{ contact.FirstName} Name"); return; } break; case UPDATE_LAST_NAME: lastName = contact.LastName; // Store the LastName of given contact in variable contact.LastName = newValue; // Update the contact with given name if (contact.Equals(contactList)) // If duplicate contact exists with that name then revert the operation { contact.LastName = lastName; Console.WriteLine($"Contact already exists with that {contact.LastName} name"); return; } break; case UPDATE_ADDRESS: contact.Address = newValue; break; case UPDATE_CITY: AddressBookDetails.cityToContactMap[contact.City].Remove(contact); // Remove the contact from city dictionary contact.City = newValue; // Update the contact city AddressBookDetails.AddToCityDictionary(contact.City, contact); // Add to city dictionary break; case UPDATE_STATE: AddressBookDetails.stateToContactMap[contact.State].Remove(contact); // Remove the contact from state dictionary contact.State = newValue; // Update the contact state AddressBookDetails.AddToStateDictionary(contact.State, contact); // Add to state dictionary break; case UPDATE_ZIP: contact.Zip = newValue; break; case UPDATE_PHONE_NUMBER: contact.PhoneNumber = newValue; break; case UPDATE_EMAIL: contact.Email = newValue; break; default: Console.WriteLine("Invalid Entry"); return; } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Record Successfully Edit and Updated "); }