Beispiel #1
0
        /// <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 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"]);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Interactively creates a new contact.
        /// </summary>
        /// <returns>The new contact.</returns>
        public static Contact Create()
        {
            string firstName = MainFunctions.GetAndValidateInput("First Name", RegexPatterns.Name);
            string lastName  = MainFunctions.GetAndValidateInput("Last Name", RegexPatterns.Name);
            string fullName  = string.Format("{0} {1}", firstName, lastName);

            Contact newContact = new Contact(fullName);

            bool addAddresses = !MainFunctions.InputStartsWith("Add addresses? (Y/n) ", "n");

            if (addAddresses)
            {
                while (true)
                {
                    Console.Clear();

                    Address newAddress = Address.Create();
                    Console.WriteLine(newAddress);

                    bool addressOK = !MainFunctions.InputStartsWith("Is this address OK? (Y/n) ", "n");

                    if (addressOK)
                    {
                        newContact.Addresses.Add(newAddress);
                        Console.WriteLine("Added new address to new contact's set of addresses.");
                    }
                    else
                    {
                        Console.WriteLine("Discarded new address.");
                    }

                    bool addAnother = !MainFunctions.InputStartsWith("Add another? (Y/n) ", "n");
                    if (!addAnother)
                    {
                        break;
                    }
                }
            }

            bool addPhoneNumbers = !MainFunctions.InputStartsWith("Add phone numbers? (Y/n) ", "n");

            if (addPhoneNumbers)
            {
                while (true)
                {
                    Console.Clear();

                    PhoneNumber newPhoneNumber = PhoneNumber.Create();
                    Console.WriteLine(newPhoneNumber);

                    bool addressOK = !MainFunctions.InputStartsWith("Is this phone number OK? (Y/n) ", "n");

                    if (addressOK)
                    {
                        newContact.PhoneNumbers.Add(newPhoneNumber);
                        Console.WriteLine("Added new phone number to new contact's set of phone numbers.");
                    }
                    else
                    {
                        Console.WriteLine("Discarded new phone number.");
                    }

                    bool addAnother = !MainFunctions.InputStartsWith("Add another? (Y/n) ", "n");
                    if (!addAnother)
                    {
                        break;
                    }
                }
            }

            bool addFaxNumbers = !MainFunctions.InputStartsWith("Add fax numbers? (Y/n) ", "n");

            if (addFaxNumbers)
            {
                while (true)
                {
                    Console.Clear();

                    FaxNumber newFaxNumber = FaxNumber.Create();
                    Console.WriteLine(newFaxNumber);

                    bool addressOK = !MainFunctions.InputStartsWith("Is this fax number OK? (Y/n) ", "n");

                    if (addressOK)
                    {
                        newContact.FaxNumbers.Add(newFaxNumber);
                        Console.WriteLine("Added new fax number to new contact's set of fax numbers.");
                    }
                    else
                    {
                        Console.WriteLine("Discarded new fax number.");
                    }

                    bool addAnother = !MainFunctions.InputStartsWith("Add another? (Y/n) ", "n");
                    if (!addAnother)
                    {
                        break;
                    }
                }
            }

            bool addEmailAddresses = !MainFunctions.InputStartsWith("Add email addresses? (Y/n) ", "n");

            if (addEmailAddresses)
            {
                while (true)
                {
                    Console.Clear();

                    EmailAddress newEmailAddress = EmailAddress.Create();
                    Console.WriteLine(newEmailAddress);

                    bool emailAddressOK = !MainFunctions.InputStartsWith("Is this email address OK? (Y/n) ", "n");

                    if (emailAddressOK)
                    {
                        newContact.EmailAddresses.Add(newEmailAddress);
                        Console.WriteLine("Added new email address to new contact's set of email addresses.");
                    }
                    else
                    {
                        Console.WriteLine("Discarded new email address.");
                    }

                    bool addAnother = !MainFunctions.InputStartsWith("Add another? (Y/n) ", "n");
                    if (!addAnother)
                    {
                        break;
                    }
                }
            }

            return(newContact);
        }
Beispiel #4
0
        /// <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;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Interactively modifies a contact.
        /// </summary>
        public void Edit()
        {
            bool editName = MainFunctions.InputStartsWith("Edit name? (y/N) ", "y");

            if (editName)
            {
                string firstName = MainFunctions.GetAndValidateInput("First Name", RegexPatterns.Name);
                string lastName  = MainFunctions.GetAndValidateInput("Last Name", RegexPatterns.Name);
                Name = string.Format("{0} {1}", firstName, lastName);
            }

            Console.WriteLine("\n");

            bool editAddresses = MainFunctions.InputStartsWith("Edit addresses? (y/N) ", "y");

            if (editAddresses)
            {
                foreach (Address address in Addresses)
                {
                    Console.WriteLine(address);
                    bool editAddress = MainFunctions.InputStartsWith("\nEdit this address? (y/N) ", "y");

                    if (editAddress)
                    {
                        Console.WriteLine();
                        address.Edit();
                    }
                }
            }

            Console.WriteLine("\n");

            bool editPhoneNumbers = MainFunctions.InputStartsWith("Edit phone numbers? (y/N) ", "y");

            if (editPhoneNumbers)
            {
                foreach (PhoneNumber phoneNumber in PhoneNumbers)
                {
                    Console.WriteLine(phoneNumber);
                    bool editPhoneNumber = MainFunctions.InputStartsWith("\nEdit this phone number? (y/N) ", "y");

                    if (editPhoneNumber)
                    {
                        Console.WriteLine();
                        phoneNumber.Edit();
                    }
                }
            }

            Console.WriteLine("\n");

            bool editFaxNumbers = MainFunctions.InputStartsWith("Edit fax numbers? (y/N) ", "y");

            if (editAddresses)
            {
                foreach (FaxNumber faxNumber in FaxNumbers)
                {
                    Console.WriteLine(faxNumber);
                    bool editFaxNumber = MainFunctions.InputStartsWith("\nEdit this fax number? (y/N) ", "y");

                    if (editFaxNumber)
                    {
                        Console.WriteLine();
                        faxNumber.Edit();
                    }
                }
            }

            Console.WriteLine("\n");

            bool editEmailAddresses = MainFunctions.InputStartsWith("Edit email addresses? (y/N) ", "y");

            if (editEmailAddresses)
            {
                foreach (EmailAddress emailAddress in EmailAddresses)
                {
                    Console.WriteLine(emailAddress);
                    bool editEmailAddress = MainFunctions.InputStartsWith("\nEdit this email address? (y/N) ", "y");

                    if (editEmailAddress)
                    {
                        emailAddress.Edit();
                    }
                }
            }
        }