Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Repository pattern used to write data to Sitecore's Experience Database
public class KeyInteractionsRepository : IKeyInteractionsRepository
{
public void Write(Contact contact, KeyInteractionsModel model)
{
IKeyInteractionsFacet facet = contact.GetFacet<IKeyInteractionsFacet>(KeyInteractionsFacet.FacetName);
if (model.SwatchesDownloaded != null && model.SwatchesDownloaded.Any())
{
foreach (KeyValuePair<string, string> keyValuePair in model.SwatchesDownloaded)
{
var swatch = facet.SwatchesDownloaded.Create();
swatch.DecorId = keyValuePair.Value;
swatch.RangeId = keyValuePair.Key;
}
}
if (model.VideosPlayed != null && model.VideosPlayed.Any())
{
foreach (KeyValuePair<string, string> videoPlayed in model.VideosPlayed)
{
var video = facet.VideosPlayed.Create();
video.VideoId = videoPlayed.Key;
video.VideoUrl = videoPlayed.Value;
}
}
if (model.SampleOrders != null && model.SampleOrders.Any())
{
foreach (var sampleOrder in model.SampleOrders)
{
var sampleOrdered = facet.SampleOrders.Create();
sampleOrdered.DecorId = sampleOrder.Key;
sampleOrdered.RangeId = sampleOrder.Value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment