/// <summary> /// Sort deatils by First name, City, State or Zip code /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(Personal_Details x, Personal_Details y) { Console.WriteLine("Enter choice for sorting:"); Console.WriteLine("1. FirstName 2. City 3. State 4. ZipCode"); String choice = Console.ReadLine(); int choice1 = Convert.ToInt32(choice); switch (choice1) { case 1: return(x.FirstName.CompareTo(y.FirstName)); case 2: return(x.City.CompareTo(y.City)); case 3: return(x.State.CompareTo(y.State)); case 4: return(x.ZipCode.CompareTo(y.ZipCode)); } return(0); }
/// <summary> /// Ability to Edit existing contact using Person's first name /// </summary> /// <param name="firstName">first name.</param> public void Edit(string firstName) { int check = 0; for (int i = 0; i < this.list.Count; i++) { if (this.list[i].FirstName.Equals(firstName)) { while (check == 0) { Personal_Details person = this.list[i]; Console.WriteLine(person); Console.WriteLine("Enter your choice for editing: "); Console.WriteLine("1.Address 2.City 3.State 4.Zip Code 5.Phone Number 6.Email ID 7.Exit"); string choice = Console.ReadLine(); int ch = Convert.ToInt32(choice); switch (ch) { case 1: Console.WriteLine("Enter new Address:"); string address = Console.ReadLine(); person.Address = address; break; case 2: Console.WriteLine("Enter new City:"); string city = Console.ReadLine(); person.City = city; break; case 3: Console.WriteLine("Enter new State:"); string state = Console.ReadLine(); person.State = state; break; case 4: Console.WriteLine("Enter new ZipCode:"); string zipCode = Console.ReadLine(); person.ZipCode = zipCode; break; case 5: Console.WriteLine("Enter new Phone Number:"); string phoneNumber = Console.ReadLine(); person.PhoneNumber = phoneNumber; break; case 6: Console.WriteLine("Enter new Email ID:"); string emailID = Console.ReadLine(); person.EmailID = emailID; break; case 7: check = 1; break; } } } } }
/// <summary> /// Ability to Add new Contact in Address Book /// </summary> public void Add() { Console.WriteLine("Enter first name"); string firstName = Console.ReadLine(); if (!Regex.Match(firstName, "^[A-Z][a-z]{2,}$").Success) { Console.WriteLine("First letter should be capital and minimum 3 characters are required\n"); } ///Ability to ensure there is no Duplicate Entry of the same Person foreach (Personal_Details personal_Details in list.FindAll(e => e.FirstName == firstName)) { Console.WriteLine("You entered Duplicate Name..."); return; } Console.WriteLine("Enter last name"); string lastName = Console.ReadLine(); if (!Regex.Match(lastName, "^[A-Z][a-z]{2,}$").Success) { Console.WriteLine("First letter should be capital\n"); } 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 Zip Code"); string zipCode = Console.ReadLine(); if (!Regex.Match(zipCode, "^[1-9]{3}[0-9]{3}$").Success) { Console.WriteLine("Zip Code contains 6 digits\n"); } Console.WriteLine("Enter phoneNumber"); string phoneNumber = Console.ReadLine(); if (!Regex.Match(phoneNumber, "^[0-9]{10}").Success) { Console.WriteLine("Invalid Phone Number\n"); } ///Duplicate Entries like Phone Number are not Allowed. foreach (Personal_Details personal_Details in list.FindAll(e => e.PhoneNumber == phoneNumber)) { Console.WriteLine("You entered Duplicate Phone Number..."); return; } Console.WriteLine("Enter EmailID"); string emailID = Console.ReadLine(); if (!Regex.Match(emailID, "^[0-9a-zA-Z]+([._+-][0-9a-zA-Z]+)*@[0-9a-zA-Z]+[.]+([a-zA-Z]{2,4})+[.]*([a-zA-Z]{2})*$").Success) { Console.WriteLine("Invalid Email ID \n"); } Console.WriteLine("Your details are Added Successfully..."); this.person = new Personal_Details(firstName, lastName, address, city, state, zipCode, phoneNumber, emailID); this.list.Add(this.person); }