/// <summary> /// Interactively modifies a phone number. /// </summary> public virtual void Edit() { bool editType = MainFunctions.InputStartsWith("Edit phone number type? (y/N) ", "y"); if (editType) { string typeOfPhoneNumberAsString = MainFunctions.ReadLine("Type: (Home/work/mobile/other) ").ToLower(); char firstLetter = 'h'; PhoneNumberType typeOfPhoneNumber = PhoneNumberType.Home; try { firstLetter = typeOfPhoneNumberAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfPhoneNumber = PhoneNumberType.Work; break; case 'm': typeOfPhoneNumber = PhoneNumberType.Mobile; break; case 'o': typeOfPhoneNumber = PhoneNumberType.Other; break; default: Console.WriteLine("Keeping default of Home"); break; } TypeOfPhoneNumber = typeOfPhoneNumber; } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Home"); } } Console.WriteLine(); bool editNumber = MainFunctions.InputStartsWith("Edit number? (y/N) ", "y"); if (editNumber) { Number = MainFunctions.GetAndValidateInput("Phone Number", RegexPatterns.PhoneNumber); } }
/// <summary> /// Interactively creates a new address. /// </summary> /// <returns>The new address.</returns> public static Address Create() { string typeOfAddressAsString = MainFunctions.ReadLine("Type: (Home/work/other) ").ToLower(); char firstLetter = 'h'; AddressType typeOfAddress = AddressType.Home; try { firstLetter = typeOfAddressAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfAddress = AddressType.Work; break; case 'o': typeOfAddress = AddressType.Other; break; default: Console.WriteLine("Keeping default of Home"); break; } } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Home"); } string streetAddress = MainFunctions.GetAndValidateInput("Street Address", RegexPatterns.Address["Street Address"]); string city = MainFunctions.GetAndValidateInput("City", RegexPatterns.Address["City"]); string state = MainFunctions.GetAndValidateInput("State", RegexPatterns.Address["State"]); string postalCode = MainFunctions.GetAndValidateInput("Postal Code", RegexPatterns.Address["Postal Code"]); Address newAddress = typeOfAddress == AddressType.Home ? new Address(streetAddress, city, state, postalCode) : new Address(typeOfAddress, streetAddress, city, state, postalCode); return(newAddress); }
/// <summary> /// Interactively creates a new phone number. /// </summary> /// <returns>The new phone number.</returns> public static PhoneNumber Create() { string typeOfPhoneNumberAsString = MainFunctions.ReadLine("Type: (Home/work/mobile/other) ").ToLower(); char firstLetter = 'h'; PhoneNumberType typeOfPhoneNumber = PhoneNumberType.Home; try { firstLetter = typeOfPhoneNumberAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfPhoneNumber = PhoneNumberType.Work; break; case 'm': typeOfPhoneNumber = PhoneNumberType.Mobile; break; case 'o': typeOfPhoneNumber = PhoneNumberType.Other; break; default: Console.WriteLine("Keeping default of Home"); break; } } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Home"); } string number = MainFunctions.GetAndValidateInput("Phone Number", RegexPatterns.PhoneNumber); PhoneNumber newPhoneNumber = new PhoneNumber(typeOfPhoneNumber, number); return(newPhoneNumber); }
/// <summary> /// Interactively modifies an address. /// </summary> public void Edit() { bool editType = MainFunctions.InputStartsWith("Edit address type? (y/N) ", "y"); if (editType) { string typeOfAddressAsString = MainFunctions.ReadLine("Type: (Home/work/other) ").ToLower(); char firstLetter = 'h'; AddressType typeOfAddress = AddressType.Home; try { firstLetter = typeOfAddressAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfAddress = AddressType.Work; break; case 'o': typeOfAddress = AddressType.Other; break; default: Console.WriteLine("Keeping default of Home"); break; } } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Home"); } TypeOfAddress = typeOfAddress; } Console.WriteLine(); bool editStreetAddress = MainFunctions.InputStartsWith("Edit street address? (y/N) ", "y"); if (editStreetAddress) { StreetAddress = MainFunctions.GetAndValidateInput("Street Address", RegexPatterns.Address["Street Address"]); } Console.WriteLine(); bool editCity = MainFunctions.InputStartsWith("Edit city? (y/N) ", "y"); if (editCity) { City = MainFunctions.GetAndValidateInput("City", RegexPatterns.Address["City"]); } Console.WriteLine(); bool editState = MainFunctions.InputStartsWith("Edit state? (y/N) ", "y"); if (editState) { State = MainFunctions.GetAndValidateInput("State", RegexPatterns.Address["State"]); } Console.WriteLine(); bool editPostalCode = MainFunctions.InputStartsWith("Edit postal code? (y/N) ", "y"); if (editPostalCode) { PostalCode = MainFunctions.GetAndValidateInput("Postal Code", RegexPatterns.Address["Postal Code"]); } }
/// <summary> /// Interactively creates a new email address. /// </summary> /// <returns>The new email address.</returns> public static EmailAddress Create() { string typeOfEmailAddressAsString = MainFunctions.ReadLine("Type: (Personal/work/school/other) ").ToLower(); char firstLetter = 'h'; EmailAddressType typeOfEmailAddress = EmailAddressType.Personal; try { firstLetter = typeOfEmailAddressAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfEmailAddress = EmailAddressType.Work; break; case 's': typeOfEmailAddress = EmailAddressType.School; break; case 'o': typeOfEmailAddress = EmailAddressType.Other; break; default: Console.WriteLine("Keeping default of Personal"); break; } } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Personal"); } string address = ""; while (true) { string emailAddressString = MainFunctions.ReadLine("Email Address: "); try { MailAddress mailAddress = new MailAddress(emailAddressString); } catch (FormatException) { Console.Write("Invalid email address. Press any key to retry..."); Console.ReadKey(); Console.Clear(); continue; } catch (ArgumentException) { Console.Write("Invalid email address. Press any key to retry..."); Console.ReadKey(); Console.Clear(); continue; } address = emailAddressString; break; } EmailAddress newEmailAddress = new EmailAddress(typeOfEmailAddress, address); return(newEmailAddress); }
/// <summary> /// Interactively modifies an email address. /// </summary> public void Edit() { bool editType = MainFunctions.InputStartsWith("Edit email address type? (y/N) ", "y"); if (editType) { string typeOfEmailAddressAsString = MainFunctions.ReadLine("Type: (Personal/work/school/other) ").ToLower(); char firstLetter = 'h'; EmailAddressType typeOfEmailAddress = EmailAddressType.Personal; try { firstLetter = typeOfEmailAddressAsString.ToCharArray()[0]; switch (firstLetter) { case 'w': typeOfEmailAddress = EmailAddressType.Work; break; case 's': typeOfEmailAddress = EmailAddressType.School; break; case 'o': typeOfEmailAddress = EmailAddressType.Other; break; default: Console.WriteLine("Keeping default of Personal"); break; } } catch (IndexOutOfRangeException) { Console.WriteLine("Keeping default of Personal"); } TypeOfEmailAddress = typeOfEmailAddress; } Console.WriteLine(); bool editAddress = MainFunctions.InputStartsWith("Edit address? (y/N) ", "y"); if (editAddress) { string address = ""; while (true) { string emailAddressString = MainFunctions.ReadLine("Email Address: "); try { MailAddress mailAddress = new MailAddress(emailAddressString); } catch (FormatException) { Console.Write("Invalid email address. Press any key to retry..."); Console.ReadKey(); Console.Clear(); continue; } catch (ArgumentException) { Console.Write("Invalid email address. Press any key to retry..."); Console.ReadKey(); Console.Clear(); continue; } address = emailAddressString; break; } Address = address; } }