コード例 #1
0
        /// <summary>
        /// Interactively creates a new fax number.
        /// </summary>
        /// <returns>The new fax number.</returns>
        public new static FaxNumber Create()
        {
            string number = MainFunctions.GetAndValidateInput("Fax Number", RegexPatterns.PhoneNumber);

            FaxNumber newFaxNumber = new FaxNumber(number);

            return(newFaxNumber);
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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"]);
            }
        }
コード例 #6
0
 /// <summary>
 /// Interactively modifies a fax number.
 /// </summary>
 public override void Edit()
 {
     Number = MainFunctions.GetAndValidateInput("Fax Number", RegexPatterns.PhoneNumber);
 }
コード例 #7
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);
        }
コード例 #8
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();
                    }
                }
            }
        }