Ejemplo n.º 1
0
        private void ConvertContacts(string companyLocale, Dictionary <int, OrganizationEntity> organizationsById, Dictionary <int, ContactEntity> contactsById)
        {
            Dictionary <string, OrganizationEntity> organizationsByName = new Dictionary <string, OrganizationEntity>();

            if (organizationsById != null && organizationsByName != null)
            {
                foreach (OrganizationEntity organization in organizationsById.Values)
                {
                    organizationsByName.Add(organization.Name, organization);
                }
            }

            Regex urlValidator = new Regex("^[\\w-_./:\\?&=]+");

            foreach (VCard vcard in VCard.List())
            {
                int vcardId = vcard.VCardId;

                ContactEntity contact = BusinessManager.InitializeEntity <ContactEntity>(ContactEntity.GetAssignedMetaClassName());

                SafelySetStringProperty(contact, "FullName", vcard.FullName);
                SafelySetStringProperty(contact, "NickName", vcard.NickName);
                if (!string.IsNullOrEmpty(vcard.Url) && urlValidator.IsMatch(vcard.Url))
                {
                    SafelySetStringProperty(contact, "WebSiteUrl", vcard.Url);
                }
                if (vcard.Birthday != DateTime.MinValue)
                {
                    contact.BirthDate = vcard.Birthday;
                }
                SafelySetStringProperty(contact, "JobTitle", vcard.Title);
                SafelySetStringProperty(contact, "Role", vcard.Role);
                SafelySetStringProperty(contact, "Description", vcard.Description);
                contact.Gender = ConvertGender(vcard.Gender);

                ConvertVCardName(vcardId, contact);
                ConvertVCardAddress(vcardId, contact, companyLocale);
                ConvertVCardPhones(vcardId, contact);
                ConvertVCardEmails(vcardId, contact);
                ConvertVCardOrganization(vcard, contact, organizationsById, organizationsByName);

                // Save contact
                contact.PrimaryKeyId = BusinessManager.Create(contact);

                contactsById.Add(vcardId, contact);
            }
        }