Example #1
0
        private static void AddContact()
        {
            using (var client = GetClient())
            {
                var identifiers = new ContactIdentifier[]
                {
                    new ContactIdentifier("twitter", "longhorntaco", ContactIdentifierType.Known),
                    new ContactIdentifier("domain", "longhorn.taco", ContactIdentifierType.Known)
                };
                var contact = new Contact(identifiers);

                var personalInfoFacet = new PersonalInformation
                {
                    FirstName = "Longhorn",
                    LastName  = "Taco"
                };
                client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                var emailFacet = new EmailAddressList(new EmailAddress("*****@*****.**", true), "twitter");
                client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet);

                client.AddContact(contact);
                client.Submit();
            }
        }
Example #2
0
        public bool Identify(string knownSource, string knownIdentifier, string newSource, string newIdentifier)
        {
            using (XConnectClient client = GetClient())
            {
                try
                {
                    IdentifiedContactReference reference = new IdentifiedContactReference(knownSource, knownIdentifier);

                    Contact existingContact = client.Get <Contact>(
                        reference,
                        new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey }));

                    if (existingContact == null)
                    {
                        return(false);
                    }

                    var identifier = new ContactIdentifier(newSource, newIdentifier, ContactIdentifierType.Known);

                    client.AddContactIdentifier(existingContact, identifier);

                    client.Submit();

                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
        protected override void ProcessContact(Contact contact)
        {
            Log.Logger.Debug($"Started processing contact {contact.Id}");
            ContactIdentifier identifier =
                contact.Identifiers.FirstOrDefault(i => i.Source == _config.IdentifierSource);

            if (identifier != null || contact.Interactions.Any(i => i.EndDateTime > DateTime.UtcNow.AddYears(-1)))
            {
                Contact existingContact = SearchContact(contact);
                if (existingContact != null)
                {
                    Log.Logger.Debug($"Found a contact for {contact.Id}, updating");
                    UpdateContact(existingContact, contact);
                }
                else
                {
                    Log.Logger.Debug($"Contact {contact.Id} is new, adding");
                    AddContact(contact);
                }
            }
            else
            {
                Log.Logger.Information($"Contact {contact.Id} was skipped");
                CurrentStatus.SkippedCounterAdd(1);
            }
        }
Example #4
0
        private async Task CreateContact()
        {
            Console.WriteLine("Enter the contact's demo identifier");
            var identifier = Console.ReadLine();

            var contactIdentifier = new ContactIdentifier("demo", identifier, ContactIdentifierType.Known);

            _contact = new Contact(contactIdentifier);

            var firstName = identifier;

            if (firstName[0] > 'Z')
            {
                firstName = firstName[0].ToString().ToUpper() + firstName.Substring(1);
            }

            var personalFacet = _contact.Personal() ?? new PersonalInformation();;

            personalFacet.FirstName = firstName;
            personalFacet.LastName  = "Smith";

            using (var client = await CreateXConnectClient())
            {
                client.AddContact(_contact);
                client.SetFacet(_contact, personalFacet);
                await client.SubmitAsync(CancellationToken.None);
            }

            Console.WriteLine($"Contact created with identifier (demo, {identifier})");
        }
Example #5
0
        //protected override string UnsubscribeContact(ContactIdentifier contactIdentifier, Guid messageID)
        //{
        //  SupportUnsubscribeMessage unsubscribeMessage = new SupportUnsubscribeMessage
        //  {
        //    AddToGlobalOptOutList = true,
        //    ContactIdentifier = contactIdentifier,
        //    MessageId = messageID,
        //    MessageLanguage = LanguageName
        //  };
        //  base.ClientApiService.Unsubscribe(unsubscribeMessage);
        //  return (ExmContext.Message.ManagerRoot.GetConfirmativePageUrl() ?? "/");
        //}

        protected override string VerifyContactSubscriptions(ContactIdentifier contactIdentifier, Guid messageID)
        {
            var result = base.VerifyContactSubscriptions(contactIdentifier, messageID);

            if (string.IsNullOrEmpty(result))
            {
                return(result);
            }

            #region Sitecore.Support.224113

            string   alreadyItemPath = ExmContext.Message.ManagerRoot.Settings.AlreadyUnsubscribedPage;
            Item     alreadyItem     = Database.GetDatabase("web").GetItem(alreadyItemPath);
            string   itemUrl         = String.Empty;
            SiteInfo site            = null;
            var      siteInfoList    = Sitecore.Configuration.Factory.GetSiteInfoList();
            foreach (SiteInfo siteInf in siteInfoList)
            {
                if (siteInf.RootPath.ToLowerInvariant().Trim() != "" && siteInf.StartItem.ToLowerInvariant().Trim() != "" && alreadyItem.Paths.FullPath.ToLowerInvariant().Trim().Contains(siteInf.RootPath.ToLowerInvariant().Trim() + siteInf.StartItem.ToLowerInvariant().Trim()))
                {
                    site = siteInf;
                }
            }

            using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext(site.Name)))
            {
                itemUrl = LinkManager.GetItemUrl(alreadyItem);
            }
            return(itemUrl);

            #endregion
        }
Example #6
0
        public Sitecore.XConnect.Contact CreateContact(string email)
        {
            var reference = new ContactIdentifier("emailaddress", email, ContactIdentifierType.Known);
            var contact   = new Sitecore.XConnect.Contact(reference);

            return(contact);
        }
        public static void AddContact(string contactIdentifier)
        {
            using (var client = Client.GetClient())
            {
                var identifiers = new ContactIdentifier[]
                {
                    new ContactIdentifier("VoiceApp", contactIdentifier, ContactIdentifierType.Known)
                };
                var contact = new Contact(identifiers);

                var personalInfoFacet = new PersonalInformation
                {
                    FirstName = "Test",
                    LastName  = "User"
                };
                client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                //assuming contact identifier is an email value
                var emailFacet = new EmailAddressList(new EmailAddress(contactIdentifier, true), "hackathon");
                client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet);

                client.AddContact(contact);
                client.Submit();
            }
        }
Example #8
0
        public async System.Threading.Tasks.Task CreateAsync(string source, string identifier)
        {
            ContactIdentifier contactIdentifier = new ContactIdentifier(source, identifier, ContactIdentifierType.Known);
            var Identifier      = contactIdentifier.Identifier;
            var XConnectContact = new Contact(new ContactIdentifier[] { contactIdentifier });

            XConnectConfigHelper        configHelper = new XConnectConfigHelper();
            XConnectClientConfiguration cfg          = await configHelper.ConfigureClient();

            using (var Client = new XConnectClient(cfg))
            {
                try
                {
                    var clientHelper = new XConnectClientHelper(Client);

                    if (!string.IsNullOrEmpty(Identifier))
                    {
                        XConnectContact = await clientHelper.GetXConnectContactByIdentifierAsync(CollectionConst.XConnect.ContactIdentifiers.Sources.SitecoreCinema, Identifier);
                    }

                    Client.AddContact(XConnectContact);
                }
                catch (XdbExecutionException ex)
                {
                    Sitecore.Diagnostics.Log.Error(ex.Message, this);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Create a contact
        /// </summary>
        /// <param name="cfg">The client configuration for connecting</param>
        /// <param name="twitterIdentifiers">The list of identifiers for each contact</param>'
        public virtual async Task <List <ContactIdentifier> > CreateMultipleContacts(XConnectClientConfiguration cfg, List <string> twitterIdentifiers)
        {
            //Ensure collection is non-null
            if (twitterIdentifiers == null)
            {
                twitterIdentifiers = new List <string>();
            }

            // Print out the identifier that is going to be used
            Logger.WriteLine("Creating Multiple Contacts [{0}]", twitterIdentifiers.Count);

            //Build up the list of ContactIdentifiers that will be used
            List <ContactIdentifier> contactIdentifiers = new List <ContactIdentifier>();

            foreach (var twitterId in twitterIdentifiers)
            {
                var identifier = new ContactIdentifier("twitter", twitterId, ContactIdentifierType.Known);
                contactIdentifiers.Add(identifier);
            }

            // Initialize a client using the validated configuration
            using (var client = new XConnectClient(cfg))
            {
                try
                {
                    //Create all the contact objects and add to the client
                    foreach (var contactIdentifier in contactIdentifiers)
                    {
                        // Create a new contact object from the identifier
                        var knownContact = new Contact(new ContactIdentifier[] { contactIdentifier });

                        //Add personal information
                        var personalInfoFacet = new PersonalInformation()
                        {
                            FirstName = "Myrtle", LastName = contactIdentifier.Identifier, JobTitle = "Programmer Writer", Birthdate = DateTime.Now.Date
                        };

                        //Set the personal info on the contact
                        client.SetFacet <PersonalInformation>(knownContact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                        //Add to the client
                        client.AddContact(knownContact);
                    }

                    // Submit contact
                    await client.SubmitAsync();

                    // Get the last batch that was executed
                    Logger.WriteOperations(client.LastBatch);
                }
                catch (XdbExecutionException ex)
                {
                    // Deal with exception
                    Logger.WriteError("Exception creating contacts", ex);
                }
            }

            return(contactIdentifiers);
        }
Example #10
0
        internal Contact CreateContact()
        {
            ContactIdentifier identifier = new ContactIdentifier(MarketingConst.XConnect.ContactIdentifiers.Sources.Marketing, candidate.MarketingIdentifierId, ContactIdentifierType.Known);

            var contact = new Contact(new ContactIdentifier[] { identifier });

            return(contact);
        }
        private ContactIdentifier GetSitecoreCinemaContactIdentifier()
        {
            //I think i am not identifying as correctly in the auto so the tracker doesn't know i'm known

            ContactIdentifier toReturn = Tracker.Current.Contact.Identifiers.FirstOrDefault(x => x.Source == Foundation.CollectionModel.Builder.CollectionConst.XConnect.ContactIdentifiers.Sources.SitecoreCinema);

            return(toReturn);
        }
Example #12
0
 public void UnsubscribeFromAll(ContactIdentifier contactIdentifier, ManagerRoot managerRoot)
 {
     _clientApiService.UpdateListSubscription(new UpdateListSubscriptionMessage()
     {
         ListSubscribeOperation = ListSubscribeOperation.UnsubscribeFromAll,
         ContactIdentifier      = contactIdentifier,
         MessageId     = Guid.Empty, //note: not used for unsubscribeFromAll, so it can be any guid
         ManagerRootId = managerRoot.Id
     });
 }
Example #13
0
        protected virtual void SendMail(ContactIdentifier toContact, Dictionary <string, object> customTokens, Guid messageId)
        {
            var automatedMessage = new AutomatedMessage();

            automatedMessage.ContactIdentifier = toContact;
            automatedMessage.MessageId         = messageId;
            automatedMessage.CustomTokens      = customTokens;
            automatedMessage.TargetLanguage    = Sitecore.Context.Language.Name;
            SendAutomatedMessage(automatedMessage);
        }
Example #14
0
        public void UpdateContactFacet <T>(
            ContactIdentifier contactIdentifier,
            string facetKey,
            Action <T> updateFacets,
            Func <T> createFacet)
            where T : Facet
        {
            if (contactIdentifier == null)
            {
                throw new ArgumentNullException(nameof(contactIdentifier));
            }

            _xConnectContactRepository.UpdateContactFacet(new IdentifiedContactReference(contactIdentifier.Source, contactIdentifier.Identifier), new ContactExpandOptions(facetKey), updateFacets, createFacet);
        }
Example #15
0
        public void UnsubscribeFromAll(ContactIdentifier contact, ManagerRoot managerRoot)
        {
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            if (managerRoot == null)
            {
                throw new ArgumentNullException(nameof(managerRoot));
            }

            _subscribeContactService.HandleContactUnsubscriptionFromAll(contact, managerRoot);
        }
        public bool HandleContactSubscription(Guid messageRecipientListId, ContactIdentifier messageContactIdentifier, Guid messageManagerRootId, Language messageContextLanguage, bool messageSendSubscriptionConfirmation)
        {
            if (messageContactIdentifier == null)
            {
                throw new ArgumentNullException(nameof(messageContactIdentifier));
            }

            using (new LanguageSwitcher(messageContextLanguage))
            {
                var managerRoot = _managerRootService.GetManagerRoot(messageManagerRootId);
                var contact     = _xConnectContactService.GetXConnectContact(messageContactIdentifier, PersonalInformation.DefaultFacetKey, ExmKeyBehaviorCache.DefaultFacetKey, EmailAddressList.DefaultFacetKey, ListSubscriptions.DefaultFacetKey);

                return(HandleContactSubscriptionInternal(messageRecipientListId, contact, managerRoot, messageSendSubscriptionConfirmation));
            }
        }
        public bool HandleContactUnsubscriptionFromAll(ContactIdentifier contactIdentifer, ManagerRoot managerRoot)
        {
            if (contactIdentifer == null)
            {
                throw new ArgumentNullException(nameof(contactIdentifer));
            }

            if (managerRoot == null)
            {
                throw new ArgumentNullException(nameof(managerRoot));
            }

            var contact = _xConnectContactService.GetXConnectContact(contactIdentifer, PersonalInformation.DefaultFacetKey, ExmKeyBehaviorCache.DefaultFacetKey, EmailAddressList.DefaultFacetKey, ListSubscriptions.DefaultFacetKey);

            return(_subscriptionManager.UnsubscribeFromAll(contact, managerRoot));
        }
        public Contact CreateNewContact(ContactModel newContact)
        {
            // Identifier for a 'known' contact
            var identifier = new ContactIdentifier[]
            {
                new ContactIdentifier(CollectionConst.XConnect.ContactIdentifiers.Sources.Twitter, newContact.ContactIdentifier, ContactIdentifierType.Known)
            };

            // Print out identifier that is going to be used
            Console.WriteLine("Identifier: " + identifier[0].Identifier);

            // Create a new contact with the identifier
            Contact knownContact = new Contact(identifier);

            return(knownContact);
        }
Example #19
0
        private ContactIdentifier CreateUniqueIdentifier()
        {
            const string source = "ExperienceGenerator";

            var identValue = "xGen_" + ShortGuid.NewGuid();

            var identifier = new ContactIdentifier(source, identValue, ContactIdentifierType.Known);

            var contact = _contactRepository.LoadContact(identifier.Source, identifier.Identifier);

            if (contact != null)
            {
                identifier = CreateUniqueIdentifier();
            }
            return(identifier);
        }
        /// <summary>
        /// Inserts a contact into xDb using xConnect
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public bool InsertContactAndAddContactToList(string source, string contactId, string alias, string firstName, string lastName, string title, string emailAddress, string listId)
        {
            // Identifier for a 'known' contact
            var identifier = new ContactIdentifier[]
            {
                new ContactIdentifier(source, contactId, ContactIdentifierType.Known),
                new ContactIdentifier(source + "_ALIAS", alias, ContactIdentifierType.Known)
            };

            // Create a new contact with the identifier
            var knownContact = new Sitecore.XConnect.Contact(identifier);

            var personalInfoFacet = new PersonalInformation()
            {
                Title     = title,
                FirstName = firstName,
                LastName  = lastName
            };


            Client.SetPersonal(knownContact, personalInfoFacet);

            var emailAddressList = new EmailAddressList(new EmailAddress(emailAddress, false), "SlackEmailAddress");

            Client.SetEmails(knownContact, emailAddressList);

            // if contact does not have list subscriptions then we need to add it
            if (knownContact.ListSubscriptions() == null)
            {
                var listSubscriptions = new ListSubscriptions();
                listSubscriptions.Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
                Client.SetFacet <ListSubscriptions>(knownContact, ListSubscriptions.DefaultFacetKey, listSubscriptions);
            }
            else
            {
                knownContact.ListSubscriptions().Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
            }

            Client.AddContact(knownContact);

            Client.Submit();

            // Get the last batch that was executed
            var operations = Client.LastBatch;

            return(true);
        }
        public async Task <bool> CreateContact(
            string source,
            string identifier,
            string email)
        {
            using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier);

                    var contactTask = client.GetAsync(
                        reference,
                        new ContactExpandOptions()
                        );

                    Contact existingContact = await contactTask;

                    if (existingContact != null)
                    {
                        return(false);
                    }


                    Contact contact = new Contact(new ContactIdentifier(source, identifier, ContactIdentifierType.Known));

                    var preferredEmail = new EmailAddress(email, true);
                    var emails         = new EmailAddressList(preferredEmail, "Work");

                    client.AddContact(contact);
                    client.SetEmails(contact, emails);

                    var identifierEmail = new ContactIdentifier(IdentificationSourceEmail, email, ContactIdentifierType.Known);

                    client.AddContactIdentifier(contact, identifierEmail);

                    await client.SubmitAsync();

                    return(true);
                }
                catch (XdbExecutionException ex)
                {
                    Log.Error(ex.Message, ex, this);
                    return(false);
                }
            }
        }
Example #22
0
        /// <summary>
        /// Create a contact
        /// </summary>
        /// <param name="cfg">The client configuration for connecting</param>
        /// <param name="twitterId">The identifier of the contact to create</param>'
        public virtual async Task <ContactIdentifier> CreateContact(XConnectClientConfiguration cfg, string twitterId)
        {
            // Identifier for a 'known' contact
            var identifier  = new ContactIdentifier("twitter", twitterId, ContactIdentifierType.Known);
            var identifiers = new ContactIdentifier[] { identifier };

            // Print out the identifier that is going to be used
            Logger.WriteLine("Creating Contact with Identifier:" + identifier.Identifier);



            // Initialize a client using the validated configuration
            using (var client = new XConnectClient(cfg))
            {
                try
                {
                    // Create a new contact object from the identifier
                    var knownContact = new Contact(identifiers);


                    //Add personal information
                    var personalInfoFacet = new PersonalInformation()
                    {
                        FirstName = "Myrtle", LastName = "McSitecore", JobTitle = "Programmer Writer", Birthdate = DateTime.Now.Date
                    };
                    //Set the personal info on the contact
                    client.SetFacet <PersonalInformation>(knownContact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                    //Add to the client
                    client.AddContact(knownContact);

                    // Submit contact
                    await client.SubmitAsync();

                    // Get the last batch that was executed
                    Logger.WriteOperations(client.LastBatch);
                }
                catch (XdbExecutionException ex)
                {
                    // Deal with exception
                    Logger.WriteError("Exception creating contact", ex);
                }
            }

            return(identifier);
        }
Example #23
0
        private static void AddIdentifierTest()
        {
            Guid contactId = Guid.Parse("BEC76A9E-F958-0000-0000-0520EB67E0F0");

            using (XConnectClient client = GetClient())
            {
                Contact existingContact = client.Get <Contact>(new ContactReference(contactId),
                                                               new ContactExpandOptions(new string[] { }));

                if (existingContact != null)
                {
                    var emailIdentifier = new ContactIdentifier("email", "*****@*****.**", ContactIdentifierType.Known);

                    client.AddContactIdentifier(existingContact, emailIdentifier);
                    client.Submit();
                }
            }
        }
Example #24
0
        public RecoResult Contact()
        {
            var result = new RecoResult();

            using (XConnectClient client
                       = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                var person    = _contactGenerator.CreateContact();
                var contactId = new ContactIdentifier(_contactsource, person.Identifier.ToString(), ContactIdentifierType.Known);
                var contact   = new Contact(contactId);

                var infoFacet = new PersonalInformation()
                {
                    FirstName = person.FirstName,
                    LastName  = person.LastName
                };
                client.SetFacet(contact, PersonalInformation.DefaultFacetKey, infoFacet);

                var emailFacet = new EmailAddressList(new EmailAddress(person.EmailAddress, true), _contactsource);
                client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emailFacet);

                var purchaseOutcome = new ProductPurchasedOutcome(ProductPurchasedOutcome.CustomPurchaseOutcomeDefinitionId, DateTime.UtcNow, "AUD", 0)
                {
                    ProductId = _contactGenerator.GetProductId()
                };

                var productPurchasedinteraction = new Interaction(contact, InteractionInitiator.Contact, _channelId, _userAgent);
                productPurchasedinteraction.Events.Add(purchaseOutcome);

                client.AddContact(contact);
                client.AddInteraction(productPurchasedinteraction);

                result.FirstName          = infoFacet.FirstName;
                result.LastName           = infoFacet.LastName;
                result.PurchasedProductId = purchaseOutcome.ProductId;

                client.Submit();
            }

            return(result);
        }
Example #25
0
        private void SubscribeContact(ManagerRoot managerRoot, Guid listId, ContactIdentifier contactIdentifier, List <MarketingPreference> marketingPreferences)
        {
            if (_useDoubleOptIn)
            {
                // If DoubleOptIn should be used the contact is subscribed to the selected contact list and gets a confirmation mail
                // The contact is only subscribed to the global contact list, which is used as source for the segmented lists, if he confirms the link in the mail
                var message = new SubscribeContactMessage
                {
                    RecipientListId              = listId,
                    ContactIdentifier            = contactIdentifier,
                    ManagerRootId                = managerRoot.Id,
                    SendSubscriptionConfirmation = true,
                    ContextLanguage              = Language.Current
                };
                _exmSubscriptionClientApiService.Subscribe(message);
            }

            var contact = GetXConnectContactByIdentifer(contactIdentifier);

            _marketingPreferenceService.SavePreferences(contact, marketingPreferences);
        }
        private async System.Threading.Tasks.Task CreateOneContactAsync(XConnectClient client, CandidateMockContactInfo candidateContactInfo)
        {
            try
            {
                var identifierId             = "MockContact." + Guid.NewGuid();
                ContactIdentifier identifier = new ContactIdentifier(CollectionConst.XConnect.ContactIdentifiers.Sources.SitecoreCinema, identifierId, ContactIdentifierType.Known);

                Contact contact = new Contact(new ContactIdentifier[] { identifier });
                client.AddContact(contact);

                PersonalInformation personalInfo = new PersonalInformation()
                {
                    FirstName = candidateContactInfo.FirstName,
                    LastName  = candidateContactInfo.LastName,
                    Birthdate = DateTime.Now,
                    Gender    = candidateContactInfo.Gender,
                };

                client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo);


                var emailAddress = new EmailAddress(candidateContactInfo.EmailAddress, true);
                var address      = new EmailAddressList(emailAddress, CollectionConst.XConnect.EmailPreferredKey);
                client.SetFacet(contact, EmailAddressList.DefaultFacetKey, address);

                Interaction interaction = new Interaction(contact, InteractionInitiator.Brand, CollectionConst.XConnect.Channels.RegisterInteractionCode, string.Empty);

                interaction.Events.Add(new Goal(CollectionConst.XConnect.Goals.RegistrationGoal, DateTime.UtcNow));

                client.AddInteraction(interaction);
                await client.SubmitAsync();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
        private Contact SearchContactByIdentifier(
            Contact contact,
            string identifierSource,
            string identifierTarget = null)
        {
            Contact result = null;

            if (string.IsNullOrWhiteSpace(identifierTarget))
            {
                identifierTarget = identifierSource;
            }

            ContactIdentifier identifier = contact.Identifiers.FirstOrDefault(i => i.Source == identifierSource);

            if (identifier != null)
            {
                result = _client.Get(
                    new IdentifiedContactReference(identifierTarget, identifier.Identifier),
                    GetExpandOptions());
            }

            Log.Logger.Debug($"Searching contact {contact.Id} by identifier {identifierSource} and found {result?.Id}");
            return(result);
        }
        /// <summary>
        /// Add Contact
        /// </summary>
        /// <param name="identifier">Email</param>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        public void AddContact(string identifier, string firstName, string lastName)
        {
            using (XConnectClient client = GetClient())
            {
                var identifiers = new ContactIdentifier[]
                {
                    new ContactIdentifier(Constans.xConnectApiSource, identifier, ContactIdentifierType.Known)
                };
                var contact = new Contact(identifiers);

                var personalInfoFacet = new PersonalInformation
                {
                    FirstName = firstName,
                    LastName  = lastName
                };
                client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                var emailFacet = new EmailAddressList(new EmailAddress(identifier, true), Constans.xConnectApiSource);
                client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet);

                client.AddContact(contact);
                client.Submit();
            }
        }
Example #29
0
        public void AddContact(XConnectClient client, ContactModel contactModel)
        {
            var identifiers = new ContactIdentifier[]
            {
                new ContactIdentifier("twitter", contactModel.FirstName + contactModel.LastName, ContactIdentifierType.Known)
            };
            var contact = new Contact(identifiers);

            var personalInfoFacet = new PersonalInformation
            {
                FirstName = contactModel.FirstName,
                LastName  = contactModel.LastName
            };

            client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

            var emailFacet = new EmailAddressList(new EmailAddress(contactModel.Email, true), "twitter");

            client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet);

            client.AddContact(contact);

            client.Submit();
        }
Example #30
0
        /// <summary>
        /// Create xConnect Contact
        /// </summary>
        /// <param name="user"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool CreateContact(string user, string email)
        {
            bool response = false;

            try
            {
                using (var client = GetClient())
                {
                    var identifiers = new ContactIdentifier[]
                    {
                        new ContactIdentifier(GenericConstants.ContactSource, email, ContactIdentifierType.Known)
                    };
                    var contact = new Contact(identifiers);

                    var personalInfoFacet = new PersonalInformation
                    {
                        Nickname = email
                    };
                    client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);

                    var emailFacet = new EmailAddressList(new EmailAddress(email, true), "email");
                    client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet);

                    client.AddContact(contact);
                    client.Submit();
                }
            }
            catch (Exception exception)
            {
                Sitecore.Diagnostics.Log.Error(
                    string.Format("Error Occured in the Method {0}",
                                  System.Reflection.MethodBase.GetCurrentMethod().Name),
                    exception);
            }
            return(response);
        }