Exemple #1
0
        public void AddContacts()
        {
            Contact tempContact = new Contact();

            tempContact.SetFirstName(AskTextQuestion("Enter contact first name: ", "First name cannot be blank!", false));
            tempContact.SetLastName(AskTextQuestion("Enter contact last name: ", "Last name cannot be blank!", false));
            tempContact.SetEmail(AskTextQuestion("Enter contact e-mail: ", "E-mail must be valid!", true));
            tempContact.SetPhoneNumber(AskTextQuestion("Enter contact phone number: ", "Phone number must be valid!", true));

            bool quit = false;

            do
            {
                Console.WriteLine("Do you have an address to add to this contact? (Y/N)");

                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                {
                    MailingAddress tempMailingAddress = new MailingAddress();
                    tempMailingAddress.Setup();
                    tempContact._Addresses.Add(tempMailingAddress);
                }
                else
                {
                    quit = true;
                }
            } while (quit == false);

            tempContact.Display();

            Console.WriteLine("Press 'Y' to add the contact to the contact list");

            if (Console.ReadKey(true).Key == ConsoleKey.Y)
            {
                Contacts.Add(tempContact);
            }
            else
            {
                Console.WriteLine("Contact was not added to contact list.");
                Console.ReadKey(true);
            }
        }
Exemple #2
0
        public void ModifyContacts()
        {
            bool quit         = false;
            int  contactIndex = 0;
            int  contactToJumpTo;

            if (Contacts.Count > 0)
            {
                do
                {
                    Console.Clear();
                    Console.WriteLine("< (P)revious | > (N)ext | (J)ump | (M)odify | (Q)uit");
                    Console.WriteLine("=========================================");
                    Console.WriteLine("Viewing Contact {0} of {1}", contactIndex + 1, Contacts.Count);
                    Console.WriteLine();
                    Contacts[contactIndex].Display();

                    switch (Console.ReadKey(true).Key)
                    {
                    case ConsoleKey.N:
                    case ConsoleKey.RightArrow:
                        contactIndex++;
                        if (contactIndex == Contacts.Count)
                        {
                            contactIndex--;
                        }
                        break;

                    case ConsoleKey.P:
                    case ConsoleKey.LeftArrow:
                        contactIndex--;
                        if (contactIndex == -1)
                        {
                            contactIndex++;
                        }
                        break;

                    case ConsoleKey.J:
                        contactToJumpTo = AskNumericQuestion("Type a contact to jump to [1 - " + Contacts.Count + "]: ", "Type in a valid number", 1, Contacts.Count);
                        contactIndex    = contactToJumpTo - 1;
                        break;

                    case ConsoleKey.M:
                        Console.Clear();


                        Console.WriteLine("First Name: {0} - Is this correct? (Y/N)", Contacts[contactIndex].GetFirstName());

                        if (Console.ReadKey(true).Key == ConsoleKey.N)
                        {
                            Contacts[contactIndex].SetFirstName(AskTextQuestion("Enter contact first name: ", "First name cannot be blank!", false));
                        }



                        Console.WriteLine("Last Name: {0} - Is this correct? (Y/N)", Contacts[contactIndex].GetLastName());

                        if (Console.ReadKey(true).Key == ConsoleKey.N)
                        {
                            Contacts[contactIndex].SetLastName(AskTextQuestion("Enter contact last name: ", "Last name cannot be blank!", false));
                        }


                        Console.WriteLine("E-mail: {0} - Is this correct? (Y/N)", Contacts[contactIndex].GetEmail());

                        if (Console.ReadKey(true).Key == ConsoleKey.N)
                        {
                            Contacts[contactIndex].SetEmail(AskTextQuestion("Enter contact e-mail: ", "E-mail must be valid!", true));
                        }


                        Console.WriteLine("Phone Number: {0} - Is this correct? (Y/N)", Contacts[contactIndex].GetPhoneNumber());

                        if (Console.ReadKey(true).Key == ConsoleKey.N)
                        {
                            Contacts[contactIndex].SetPhoneNumber(AskTextQuestion("Enter contact phone number: ", "Phone number must be valid!", true));
                        }



                        for (int addressIndex = 0; addressIndex < Contacts[contactIndex]._Addresses.Count; addressIndex++)
                        {
                            MailingAddress tempAddress = Contacts[contactIndex]._Addresses[addressIndex];
                            tempAddress.Display();


                            Console.WriteLine();

                            bool validInput = false;

                            do
                            {
                                Console.WriteLine("Keep this address? (Y/N)");

                                ConsoleKey userResponse = Console.ReadKey(true).Key;

                                Console.Clear();

                                switch (userResponse)
                                {
                                case ConsoleKey.Y:

                                    Console.WriteLine("Address Type: {0} - Is this correct? (Y/N)", tempAddress.GetAddressType());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetAddressType(tempAddress.AskHomeOrBusiness("What type of address is this (home or business)? ", "You must enter home or business."));
                                    }

                                    Console.WriteLine("Address Line 1: {0} - Is this correct? (Y/N)", tempAddress.GetAddressLine1());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetAddressLine1(AskTextQuestion("What is Address Line 1? ", "Address Line 1 cannot be blank!", false));
                                    }

                                    Console.WriteLine("Address Line 2: {0} - Is this correct? (Y/N)", tempAddress.GetAddressLine2());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetAddressLine2(AskTextQuestion("What is Address Line 2? ", "", true));
                                    }

                                    Console.WriteLine("City: {0} - Is this correct? (Y/N)", tempAddress.GetCity());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetCity(AskTextQuestion("What is the city? ", "City cannot be blank!", false));
                                    }

                                    Console.WriteLine("State: {0} - Is this correct? (Y/N)", tempAddress.GetState());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetState(AskTextQuestion("What is the state? ", "State cannot be blank!", false));
                                    }

                                    Console.WriteLine("ZipCode: {0} - Is this correct? (Y/N)", tempAddress.GetZipCode());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetZipCode(AskTextQuestion("What is the zip code? ", "Zip cannot be blank!", false));
                                    }

                                    Console.WriteLine("Phone Number: {0} - Is this correct? (Y/N)", tempAddress.GetPhoneNumber());

                                    if (Console.ReadKey(true).Key == ConsoleKey.N)
                                    {
                                        tempAddress.SetPhoneNumber(AskTextQuestion("What is the phone number? ", "Phone number must be valid input!", true));
                                    }


                                    validInput = true;
                                    break;

                                case ConsoleKey.N:
                                    Contacts[contactIndex]._Addresses.RemoveAt(addressIndex);
                                    Console.WriteLine("Address removed.");
                                    addressIndex--;
                                    validInput = true;
                                    break;


                                default:
                                    Console.WriteLine("Not valid input! Enter Y to Keep or N to Delete");
                                    break;
                                }
                            } while (!validInput);
                        }                                 // END ADDRESS LOOP

                        bool endAddMailingAddress = false;

                        do
                        {
                            Console.WriteLine("Do you have a mailing address to add to this contact? (Y/N)");

                            if (Console.ReadKey(true).Key == ConsoleKey.Y)
                            {
                                MailingAddress tempAddress = new MailingAddress();
                                tempAddress.Setup();

                                Contacts[contactIndex]._Addresses.Add(tempAddress);
                            }
                            else
                            {
                                endAddMailingAddress = true;
                            }
                        } while (!endAddMailingAddress);



                        break;

                    case ConsoleKey.Q:
                        quit = true;
                        break;
                    }
                } while (quit == false);
            }
            else
            {
                Console.WriteLine("There are no contacts in the contact list!");
                Console.ReadKey(true);
            }
        }