private Contact CreateContact()
        {
            var identifier = CreateUniqueIdentifier();

            var contact = _contactRepository.CreateContact(ID.NewID);

            contact.Identifiers.AuthenticationLevel = AuthenticationLevel.None;
            contact.System.Classification           = 0;
            contact.ContactSaveMode               = ContactSaveMode.AlwaysSave;
            contact.Identifiers.Identifier        = identifier;
            contact.System.OverrideClassification = 0;
            contact.System.Value      = 0;
            contact.System.VisitCount = 0;

/*
 *          var contactPreferences = contact.GetFacet<IContactPreferences>("Preferences");
 *          contactPreferences.Language = _languages;
 */
            var contactPersonalInfo = contact.GetFacet <IContactPersonalInfo>("Personal");

            contactPersonalInfo.FirstName = Name.First();
            contactPersonalInfo.Surname   = Name.Last();

            var contactEmailAddresses = contact.GetFacet <IContactEmailAddresses>("Emails");

            contactEmailAddresses.Entries.Create("Work").SmtpAddress = Internet.Email($"{contactPersonalInfo.FirstName} {contactPersonalInfo.Surname}");
            contactEmailAddresses.Preferred = "Work";

            var leaseOwner = new LeaseOwner("CONTACT_CREATE", LeaseOwnerType.OutOfRequestWorker);
            var options    = new ContactSaveOptions(true, leaseOwner, null);

            _contactRepository.SaveContact(contact, options);

            return(contact);
        }
Example #2
0
        // this will not work if the session is actio on the current delivery cluster
        public ActionResult TestRepoContactAddTestModelValue(string contactid, string echo)
        {
            Sitecore.Analytics.Data.ContactRepository repo = new Sitecore.Analytics.Data.ContactRepository();

            var c = repo.TryLoadContact(
                contactid,
                new Sitecore.Analytics.Model.LeaseOwner(
                    "TestController",
                    Sitecore.Analytics.Model.LeaseOwnerType.WebCluster),
                TimeSpan.FromSeconds(10));

            var model = c.Object.Extensions.Create <TestModel>(testKey);

            model.TestValue = echo;

            repo.SaveContact(c.Object, c.LockedBy, true);

            return(Test(model.TestValue));
        }