Beispiel #1
0
        private ContactNumber AssignNumberType(string numberType, string contactNumber)
        {
            ContactNumber number = null;

            if (numberType != null)
            {
                switch (numberType)
                {
                case "home":
                    if (contactNumber.Length == 9)
                    {
                        number = new HomeNumber(contactNumber);
                    }
                    else
                    {
                        Console.WriteLine("Wrong number length");
                    }
                    break;

                case "mobile":
                    if (contactNumber.Length == 10)
                    {
                        number = new MobileNumber(contactNumber);
                    }
                    else
                    {
                        Console.WriteLine("Wrong number length");
                    }
                    break;
                }
            }

            return(number);
        }
Beispiel #2
0
        private Contact RetrieveContactInfo()
        {
            bool    valid   = true;
            Contact contact = null;

            Console.Write("Contact first name: ");
            string firstName = Console.ReadLine().ToLower().Trim(' ');

            if (firstName == "")
            {
                Console.WriteLine("Bad first name!");
                valid = false;
            }
            if (!valid)
            {
                return(null);
            }

            Console.Write("Contact last name: ");
            string lastName = Console.ReadLine().ToLower().Trim(' ');

            if (lastName == "")
            {
                Console.WriteLine("wrong lastname");
                valid = false;
            }
            if (!valid)
            {
                return(null);
            }

            Console.Write("Contact number type {home, mobile}: ");
            string contactNumberType = Console.ReadLine().ToLower().Trim(' ');

            if (contactNumberType == "" || !(contactNumberType == "home" || contactNumberType == "mobile"))
            {
                Console.WriteLine("wrong contact number type");
                valid = false;
            }
            if (!valid)
            {
                return(null);
            }

            Console.Write("Contact number: ");
            string contactNumber = Console.ReadLine().ToLower().Trim(' ');

            Console.WriteLine();

            ContactNumber number = AssignNumberType(contactNumberType, contactNumber);

            if (firstName != null && lastName != null && number != null)
            {
                contact = new Contact(firstName, lastName, number);
            }

            return(contact);
        }
Beispiel #3
0
 public Contact(string firstName, string lastName, ContactNumber number)
 {
     this.firstName = new FirstName(firstName);
     this.lastName  = new LastName(lastName);
     this.number    = number;
 }