Esempio n. 1
0
        /// <summary>
        /// Gets the address book from CSV dictionary.
        /// </summary>
        //(This would be private, but test generation wouldn't work...)
        internal static AddressBook GetAddressBookFromLookup(IEnumerable<Dictionary<string, string>> csv)
        {
            AddressBook book = new AddressBook();
            foreach(var row in csv)
            {
                bool isbusiness = (row[Keys.HomePhone] == "" && row[Keys.WorkPhone] != ""); //is business if no home phone AND has business phone
                bool multiperson = row[Keys.FirstName].Contains('&');
                var contact = new Contact
                {
                    Name = row[Keys.LastName],
                    Email = ContactMailLogic(row, multiperson),
                    IsBusiness = isbusiness,
                    PhoneNumber = isbusiness ? row[Keys.WorkPhone] : row[Keys.HomePhone],
                    Address = GetAddress(row),
                    Notes = row[Keys.Notes]
                };
                //Add one or two people, based on first name containing &
                if(multiperson)
                {
                    contact.AddPerson(FirstPerson(row, false));
                    contact.AddPerson(SecondPerson(row));
                }
                else
                {
                    contact.AddPerson(FirstPerson(row, true));
                }

                //Update first names with new people
                contact.UpdateFirstNames();
                book.AddContact(contact);
            }

            return book;
        }