Exemplo n.º 1
0
        public static Contact ToContact(this VCard vcard, string tenant, Guid contactId)
        {
            if (vcard == null)
            {
                return(new Contact());
            }

            var contact = new Contact
            {
                ContactId          = contactId,
                Title              = vcard.Title,
                Role               = vcard.Role,
                FirstName          = vcard.FirstName,
                LastName           = vcard.LastName,
                MiddleName         = vcard.MiddleName,
                Prefix             = vcard.Prefix,
                Suffix             = vcard.Suffix,
                NickName           = vcard.NickName,
                FormattedName      = vcard.FormattedName,
                Url                = vcard.Url?.ToString(),
                Kind               = vcard.Kind,
                Gender             = vcard.Gender,
                Language           = vcard.GetPreferredLanguage(),
                TimeZone           = vcard.TimeZone?.StandardName,
                Organization       = vcard.Organization,
                OrganizationalUnit = vcard.OrganizationalUnit,
                EmailAddresses     = vcard.GetEmailAddresses(),
                Telephones         = vcard.GetTelephones(),
                MobileNumbers      = vcard.GetMobileNumbers(),
                FaxNumbers         = vcard.GetFaxNumbers(),
                Note               = vcard.Note,
                BirthDay           = vcard.BirthDay,
                Tags               = string.Join(",", vcard.Categories.Coalesce(new[] { "" })),
                IsPrivate          = vcard.Classification != ClassificationType.Public
            };

            vcard.SavePhoto(tenant, contactId);

            if (vcard.Addresses == null || !vcard.Addresses.Any())
            {
                return(contact);
            }

            var address = vcard.Addresses.OrderBy(x => x.Preference).FirstOrDefault();

            if (address == null)
            {
                return(contact);
            }

            contact.PostalCode   = address.PostalCode;
            contact.AddressLine1 = address.ExtendedAddress;
            contact.Street       = address.Street;
            contact.City         = address.Locality;
            contact.State        = address.Region;
            contact.Country      = address.Country;


            return(contact);
        }