/// <summary> /// Set emotion facet to contact /// </summary> /// <param name="contact">Contact to be updated</param> /// <param name="facet">Facet to be applied to Contact</param> public void SetEmotionFacet(Contact contact, EmotionFacet facet) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { try { var emotions = contact.GetFacet <EmotionFacet>(EmotionFacet.DefaultFacetKey); if (emotions == null) { client.SetFacet(contact, EmotionFacet.DefaultFacetKey, facet); } else { UpdateFacetValues(facet, emotions); client.SetFacet(contact, EmotionFacet.DefaultFacetKey, emotions); } client.Submit(); } catch (XdbExecutionException ex) { Log.Error($"Could not set facet for {contact.Id} contact", ex, this); } } }
private static void UpdateFacetValues(EmotionFacet facet, EmotionFacet emotions) { emotions.Anger = facet.Anger; emotions.Disgust = facet.Disgust; emotions.Fear = facet.Fear; emotions.Feeling = facet.Feeling; emotions.Happiness = facet.Happiness; emotions.Neutral = facet.Neutral; emotions.Sadness = facet.Sadness; emotions.Surprise = facet.Surprise; }