public void UpdateXDbContactEmail(IXDbContactWithEmail basicContact)
 {
     using (var client = SitecoreXConnectClientConfiguration.GetClient())
     {
         var reference  = new IdentifiedContactReference(basicContact.IdentifierSource, basicContact.IdentifierValue);
         var xDbContact = client.Get(reference, new ContactExpandOptions(CollectionModel.FacetKeys.PersonalInformation, CollectionModel.FacetKeys.EmailAddressList));
         SetEmail(xDbContact, basicContact, client);
         client.Submit();
     }
 }
 public void UpdateOrCreateXDbServiceContactWithEmail(IXDbContactWithEmail serviceContact)
 {
     using (var client = SitecoreXConnectClientConfiguration.GetClient())
     {
         var reference = new IdentifiedContactReference(serviceContact.IdentifierSource, serviceContact.IdentifierValue);
         var contact   = client.Get(reference, new ContactExpandOptions(CollectionModel.FacetKeys.EmailAddressList));
         if (contact == null)
         {
             contact = new Contact(new ContactIdentifier(reference.Source, reference.Identifier, ContactIdentifierType.Known));
             SetEmail(contact, serviceContact, client);
             client.AddContact(contact);
             client.Submit();
         }
         else if (contact.Emails()?.PreferredEmail.SmtpAddress != serviceContact.Email)
         {
             SetEmail(contact, serviceContact, client);
             client.Submit();
         }
     }
 }
        private static void SetEmail(Contact contact, IXDbContactWithEmail xDbContact, IXdbContext client)
        {
            if (string.IsNullOrEmpty(xDbContact.Email))
            {
                return;
            }
            var emailFacet = contact.Emails();

            if (emailFacet == null)
            {
                emailFacet = new EmailAddressList(new EmailAddress(xDbContact.Email, false), "Preferred");
            }
            else
            {
                if (emailFacet.PreferredEmail?.SmtpAddress == xDbContact.Email)
                {
                    return;
                }
                emailFacet.PreferredEmail = new EmailAddress(xDbContact.Email, false);
            }
            client.SetEmails(contact, emailFacet);
        }
 public void UpdateOrCreateServiceContact(IXDbContactWithEmail contact)
 {
     CheckIdentifier(contact);
     xDbContactRepository.UpdateOrCreateXDbServiceContactWithEmail(contact);
 }
 public void UpdateEmail(IXDbContactWithEmail contact)
 {
     CheckIdentifier(contact);
     xDbContactRepository.UpdateXDbContactEmail(contact);
 }