/// <summary> /// Displays the contact details. /// </summary> public void SearchContactDetails() { // If the List doesnt have any contacts // Else get the name to search for details if (contactList.Count() == 0) { Console.WriteLine("No saved contacts"); return; } Console.WriteLine("\nEnter the name of candidate to get Details"); string name = Console.ReadLine().ToLower(); logger.Info("User searched for a contact " + name); // Search the contact by name ContactDetails contact = SearchByName(name); // If contact doesnt exist if (contact == null) { Console.WriteLine("No record found"); return; } // Print the details of the contact after search contact.toString(); }
/// <summary> /// Removes the contact. /// </summary> public void RemoveContact() { // If the List does not have any contacts if (contactList.Count() == 0) { Console.WriteLine("No saved contacts"); return; } // Input the name of the contact to be removed Console.WriteLine("\nEnter the name of contact to be removed"); string name = Console.ReadLine().ToLower(); logger.Info("User requested to remove contact " + name); // Search for the contact ContactDetails contact = SearchByName(name); // If contact doesnt exist if (contact == null) { Console.WriteLine("No record found"); return; } // Print the details of contact for confirmation contact.toString(); // Asking for confirmation to delete contact // If user says yes(y) then delete the contact Console.WriteLine("Press y to confirm delete or any other key to abort"); switch (Console.ReadLine().ToLower()) { case "y": contactList.Remove(contact); AddressBookDetails.cityToContactMap[contact.City].Remove(contact); AddressBookDetails.stateToContactMap[contact.State].Remove(contact); Console.WriteLine("Contact deleted"); logger.Info("User removed the contact"); break; default: Console.WriteLine("Deletion aborted"); logger.Info("User aborted the process"); break; } }
/// <summary> /// Updates the contact. /// </summary> public void UpdateContact() { // If the List have no contacts if (contactList.Count() == 0) { Console.WriteLine("No saved contacts"); return; } // Input the name to be updated Console.WriteLine("\nEnter the name of candidate to be updated"); string name = Console.ReadLine(); logger.Info("User tried to update contact" + name); // Search the name ContactDetails contact = SearchByName(name); // If contact doesnt exist if (contact == null) { Console.WriteLine("No record found"); return; } // To print details of searched contact contact.toString(); int updateAttributeNum = 0; // Getting the attribute to be updated Console.WriteLine("\nEnter the row number attribute to be updated or 0 to exit"); try { updateAttributeNum = Convert.ToInt32(Console.ReadLine()); if (updateAttributeNum == 0) { return; } } catch { Console.WriteLine("Invalid entry"); return; } // Getting the new value of attribute Console.WriteLine("\nEnter the new value to be entered"); string newValue = Console.ReadLine(); // Updating selected attribute with selected value switch (updateAttributeNum) { case UPDATE_FIRST_NAME: // Store the firstname of given contact in variable firstName = contact.FirstName; // Update the contact with given name contact.FirstName = newValue; // If duplicate contact exists with that name then revert the operation if (contact.Equals(contactList)) { contact.FirstName = firstName; Console.WriteLine("Contact already exists with that name"); return; } break; case UPDATE_LAST_NAME: // Store the LastName of given contact in variable lastName = contact.LastName; // Update the contact with given name contact.LastName = newValue; // If duplicate contact exists with that name then revert the operation if (contact.Equals(contactList)) { contact.LastName = lastName; Console.WriteLine("Contact already exists with that name"); return; } break; case UPDATE_ADDRESS: contact.Address = newValue; break; case UPDATE_CITY: // Remove the contact from city dictionary AddressBookDetails.cityToContactMap[contact.City].Remove(contact); // Update the contact city contact.City = newValue; // Add to city dictionary AddressBookDetails.AddToCityDictionary(contact.City, contact); break; case UPDATE_STATE: // Remove the contact from state dictionary AddressBookDetails.stateToContactMap[contact.State].Remove(contact); // Update the contact state contact.State = newValue; // Add to state dictionary AddressBookDetails.AddToStateDictionary(contact.State, contact); 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; } logger.Info("User updated contact"); Console.WriteLine("\nUpdate Successful"); }