This is yet another post on the focal point of Sitecore 8: Contacts. The contact repository is a multi-usage storage of user information, from visitors (named and anonymous) to imported email addresses to be used in email campaigns.
The Sitecore List Manager is a part of EXM (Email Experience Manager) and replaces .NET security roles as segmentation. In Sitecore 8, you do not need a .NET user to send a mail to a person, all you need is a Contact.
To send an email to more than one person you create a list, add Contacts, create an email, select the list and send the email.
A ContactList is no more than a Facet on the Contact. The facet contains the GUID of the Contact List Item and a timestamp:
So because the list is not actually a list but a set of unconnected GUID’s on unconnected Contacts, it is very easy to add and remove users from Contacts (thanks to Michael Sundstrøm for the code):
using System.Collections.Generic; using Sitecore.Analytics.Model.Entities; using Sitecore.Analytics.Tracking; using Sitecore.Data; using Sitecore.Data.Items; using Sitecore.SecurityModel; namespace MyNamespace { public class ContactListRepository { private const string _CONTACT_LIST_TAG_NAME = "ContactLists"; public IEnumerable<Item> Get(Contact contact, Database database) { ITag tag = contact.Tags.Find(_CONTACT_LIST_TAG_NAME); if (tag == null) yield break; foreach (ITagValue tagValue in tag.Values) { yield return database.GetItem(tagValue.Value); } } public void Add(Contact contact, Item listItem) { using (new SecurityDisabler()) { contact.Tags.Set(_CONTACT_LIST_TAG_NAME, listItem.ID.ToString()); } } public void Remove(Contact contact, Item listItem) { using (new SecurityDisabler()) { contact.Tags.Remove(_CONTACT_LIST_TAG_NAME, listItem.ID.ToString()); } } } }
So how to Sitecore make these unconnected GUID’s into lists? Each time you add data to the xDB (MongoDB), Sitecore updates the index, Lucene.NET or SOLR. Data is also always queried through the index which is why Sitecore does not need a separate List collection in MongoDB.
MORE TO READ:
- Sitecore 8 EXM add a contact to list from listmanager from Stackoverflow.
- Sitecore Contacts – Create and save contacts to and from xDB (MongoDB) by briancaos
- Sitecore contact facets – Create your own facet by briancaos
