Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Last active December 7, 2015 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save islaytitans/a32399dd4eec1cad2318 to your computer and use it in GitHub Desktop.
Save islaytitans/a32399dd4eec1cad2318 to your computer and use it in GitHub Desktop.
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