private static void AddContact() { using (var client = GetClient()) { var contact = new Contact(new ContactIdentifier("domain", "docker.examples", ContactIdentifierType.Known)); var personalInfo = new PersonalInformation { FirstName = "Docker", LastName = "Examples" }; client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo); var emailFacet = new EmailAddressList(new EmailAddress("*****@*****.**", true), "domain"); client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emailFacet); // Add our custom facet var demoFacet = new DemoFacet { FavoriteAnimal = "Whale" }; client.SetFacet(contact, DemoFacet.DefaultFacetKey, demoFacet); client.AddContact(contact); client.Submit(); Console.WriteLine("Added contact!"); } }
private static void SetEmail(Sitecore.XConnect.Contact contact, IXConnectContactWithEmail xConnectContact, IXdbContext client) { if (string.IsNullOrEmpty(xConnectContact.Email)) { return; } var facet = contact.Emails(); if (facet == null) { facet = new EmailAddressList(new EmailAddress(xConnectContact.Email, false), "Preferred"); } else { if (facet.PreferredEmail?.SmtpAddress == xConnectContact.IdentifierValue) { return; } facet.PreferredEmail = new EmailAddress(xConnectContact.Email, false); } client.SetEmails(contact, facet); }
/// <summary> /// Sets the <see cref="EmailAddressList"/> facet of the specified <paramref name="contact" />. /// </summary> /// <param name="email">The email address.</param> /// <param name="contact">The contact.</param> /// <param name="client">The client.</param> private static void SetEmail(string email, Contact contact, IXdbContext client) { if (string.IsNullOrEmpty(email)) { return; } EmailAddressList emailFacet = contact.Emails(); if (emailFacet == null) { emailFacet = new EmailAddressList(new EmailAddress(email, false), "Preferred"); } else { if (emailFacet.PreferredEmail?.SmtpAddress == email) { return; } emailFacet.PreferredEmail = new EmailAddress(email, false); } client.SetEmails(contact, emailFacet); }
private void SetPreferredEmail(string key, string email) { var reference = this.GetCurrentContactReference(); using (var client = SitecoreXConnectClientConfiguration.GetClient()) { var contact = client.Get(reference, new ExpandOptions(EmailAddressList.DefaultFacetKey)); var emailAddress = new EmailAddress(email, true); var emailAddressList = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); if (emailAddressList == null) { emailAddressList = new EmailAddressList(emailAddress, key); } else { emailAddressList.PreferredKey = key; emailAddressList.PreferredEmail = emailAddress; } client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emailAddressList); client.Submit(); } }
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(); } }
public EmailAddressList MakeFacetEmailAddressList() { var emailAddress = new EmailAddress(candidate.EmailAddress, true); var emailAddressList = new EmailAddressList(emailAddress, MarketingConst.XConnect.EmailKeys.Work); return(emailAddressList); }
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(); } }
// Evaluates condition for single contact public bool Evaluate(IRuleExecutionContext context) { var contact = context.Fact <Contact>(); EmailAddressList emails = CollectionModel.Emails(RuleExecutionContextExtensions.Fact <Contact>(context, null)); return(emails?.PreferredEmail == null ? false : emails.PreferredEmail.Validated); }
public override ActivityResult Invoke(IContactProcessingContext context) { EmailAddressList facet = context.Contact.GetFacet <EmailAddressList>(); if (facet == null) { return((ActivityResult) new Failure(Resources.TheEmailAddressListFacetHasNotBeenSetSuccessfully)); } string email = facet.PreferredEmail.SmtpAddress; LoggerExtensions.LogInformation(this.Logger, "processing agenda email for: " + email); //Get agenda url string urlformat = ConfigurationManager.AppSettings["agendaurlformat"]; //add contact id as parameter Guid?contactID = context.Contact.Id; string url = string.Format(urlformat, contactID); LoggerExtensions.LogInformation(this.Logger, "processing agenda for url: " + url); //make request, get body, send email var emailService = new EmailService(); var sended = emailService.SendSmtpEmail(email, url); if (!sended) { LoggerExtensions.LogInformation(this.Logger, "Message was not sent"); } LoggerExtensions.LogDebug((ILogger)this.Logger, string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.TheFacetHasBeenSetAndSubmittedSuccessfullyPattern, (object)"EmailAddressList"), Array.Empty <object>()); return((ActivityResult) new SuccessMove()); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); _to = new EmailAddressList(); _cc = new EmailAddressList(); _bcc = new EmailAddressList(); HtmlEditorDataType h = new HtmlEditorDataType(); PortalSettings pS = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; try { h.Value = pS.CustomSettings["SITESETTINGS_DEFAULT_EDITOR"].ToString(); txtBody = h.GetEditor(PlaceHolderHTMLEditor, int.Parse(Context.Request["mID"]), bool.Parse(pS.CustomSettings["SITESETTINGS_SHOWUPLOAD"].ToString()), pS); } catch { txtBody = h.GetEditor(PlaceHolderHTMLEditor, int.Parse(Context.Request["mID"]), true, pS); } lblEmailAddressesNotOk.Text = General.GetString("EMF_ADDRESSES_NOT_OK", "The emailaddresses are not ok.", lblEmailAddressesNotOk); }
public new IContact Get(Guid contactId) { string[] facets = new string[8] { "Personal", "Addresses", "Emails", "PhoneNumbers", "Classification", "EngagementMeasures", "SalesforceContact", "CustomSalesforceContact" }; Contact contact = this.GetContact(contactId, facets); PersonalInformation facet1 = this.TryGetFacet <PersonalInformation>(contact, "Personal"); AddressList facet2 = this.TryGetFacet <AddressList>(contact, "Addresses"); EmailAddressList facet3 = this.TryGetFacet <EmailAddressList>(contact, "Emails"); PhoneNumberList facet4 = this.TryGetFacet <PhoneNumberList>(contact, "PhoneNumbers"); Classification facet5 = this.TryGetFacet <Classification>(contact, "Classification"); EngagementMeasures facet6 = this.TryGetFacet <EngagementMeasures>(contact, "EngagementMeasures"); SalesforceContactInformation facet7 = this.TryGetFacet <SalesforceContactInformation>(contact, "SalesforceContact"); CustomSalesforceContactInformation facet8 = this.TryGetFacet <CustomSalesforceContactInformation>(contact, "CustomSalesforceContact"); return((IContact)this.CreateContact(contact.Id.GetValueOrDefault(), facet5, facet6, facet1, facet3, facet4, facet2, facet7, facet8, contact.Identifiers.ToList <ContactIdentifier>())); }
private static ContactIdentifier GetValueFromEmailAddressListFacet(EmailAddressList facet) { var preferredEmail = facet.PreferredEmail; var smtpAddress = preferredEmail?.SmtpAddress; return(!string.IsNullOrEmpty(smtpAddress) ? new ContactIdentifier(ContactIdentifiers.Email, facet.PreferredEmail.SmtpAddress, ContactIdentifierType.Known) : null); }
protected void setData(KeyValuePair <Guid, string> keyValuePair) { // Initialize a client using the validated configuration using (var client = XConnectHelper.GetClient()) { try { var channelId = Guid.Parse("52B75873-4CE0-4E98-B63A-B535739E6180"); // "email newsletter" channel // Create a new contact with the identifier Contact knownContact = new Contact(); PersonalInformation personalInfoFacet = new PersonalInformation(); personalInfoFacet.FirstName = "Abhi" + Guid.NewGuid().ToString(); personalInfoFacet.LastName = "Marwah"; personalInfoFacet.JobTitle = "Sitecore Architect"; personalInfoFacet.Gender = "Male"; personalInfoFacet.Nickname = "Aussie"; client.SetFacet <PersonalInformation>(knownContact, PersonalInformation.DefaultFacetKey, personalInfoFacet); EmailAddressList emails = new EmailAddressList(new EmailAddress("*****@*****.**", true), "Email"); client.SetFacet(knownContact, emails); PageViewEvent pageView = new PageViewEvent(DateTime.Now.ToUniversalTime(), keyValuePair.Key, 1, "en"); pageView.ItemLanguage = "en"; pageView.Duration = new TimeSpan(3000); pageView.SitecoreRenderingDevice = new SitecoreDeviceData(new Guid("{fe5d7fdf-89c0-4d99-9aa3-b5fbd009c9f3}"), "Default"); pageView.Url = keyValuePair.Value; client.AddContact(knownContact); // Create a new interaction for that contact Interaction interaction = new Interaction(knownContact, InteractionInitiator.Brand, channelId, ""); // Add events - all interactions must have at least one event interaction.Events.Add(pageView); IpInfo ipInfo = new IpInfo("127.0.0.1"); ipInfo.BusinessName = "Sitecore Consultancy"; client.SetFacet <IpInfo>(interaction, IpInfo.DefaultFacetKey, ipInfo); // Add the contact and interaction client.AddInteraction(interaction); // Submit contact and interaction - a total of two operations client.Submit(); } catch (XdbExecutionException ex) { // Deal with exception } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event. /// </summary> /// <param name="e"> /// An <see cref="T:System.EventArgs"/> object that contains the event data. /// </param> protected override void OnInit(EventArgs e) { this.To = new EmailAddressList(); this.Cc = new EmailAddressList(); this.Bcc = new EmailAddressList(); var h = new HtmlEditorDataType(); var pS = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; try { h.Value = pS.CustomSettings["SITESETTINGS_DEFAULT_EDITOR"].ToString(); this.txtBody = h.GetEditor( this.PlaceHolderHTMLEditor, int.Parse(this.Context.Request["mID"]), bool.Parse(pS.CustomSettings["SITESETTINGS_SHOWUPLOAD"].ToString()), pS); } catch { this.txtBody = h.GetEditor(this.PlaceHolderHTMLEditor, int.Parse(this.Context.Request["mID"]), true, pS); } this.lblEmailAddressesNotOk.Text = General.GetString( "EMF_ADDRESSES_NOT_OK", "The emailaddresses are not ok.", this.lblEmailAddressesNotOk); this.txtTo.Text = string.Join(";", (string[])this.To.ToArray(typeof(string))); this.txtCc.Text = string.Join(";", (string[])this.Cc.ToArray(typeof(string))); this.txtBcc.Text = string.Join(";", (string[])this.Bcc.ToArray(typeof(string))); base.OnInit(e); }
public static void GetObjectPostAction(DataRow inputRow, DataTable table, DataObjectStore store) { DataRow dataRow = table.Rows[0]; if (dataRow["SimpleEmailAddresses"] != DBNull.Value) { dataRow["EmailAddresses"] = EmailAddressList.FromProxyAddressCollection((ProxyAddressCollection)dataRow["SimpleEmailAddresses"]); } if (dataRow["ObjectCountryOrRegion"] != DBNull.Value) { dataRow["CountryOrRegion"] = ((CountryInfo)dataRow["ObjectCountryOrRegion"]).Name; } MailboxPropertiesHelper.GetMaxSendReceiveSize(inputRow, table, store); MailboxPropertiesHelper.GetAcceptRejectSendersOrMembers(inputRow, table, store); if (dataRow["EmailAddresses"] != DBNull.Value && dataRow["RemoteRoutingAddress"] != DBNull.Value) { EmailAddressList emailAddressList = (EmailAddressList)dataRow["EmailAddresses"]; string strA = (string)dataRow["RemoteRoutingAddress"]; foreach (EmailAddressItem emailAddressItem in emailAddressList) { string identity = emailAddressItem.Identity; if (string.Compare(strA, identity, true) == 0) { dataRow["RemoteRoutingAddress"] = identity; break; } } } dataRow["IsRemoteUserMailbox"] = ((RecipientTypeDetails)((ulong)int.MinValue)).Equals(dataRow["RecipientTypeDetails"]); }
private bool SetEmail(ContactFacetData data, XConnect.Contact contact, XConnectClient client) { var email = data.EmailAddress; if (string.IsNullOrEmpty(email)) { return(false); } var emails = contact.Emails(); if (emails == null) { emails = new EmailAddressList(new EmailAddress(email, false), null); } else { if (emails.PreferredEmail?.SmtpAddress == email) { return(false); } emails.PreferredEmail = new EmailAddress(email, false); } client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emails); return(true); }
private Contact CreateContact() { var identifier = CreateUniqueIdentifier(); using (var client = GetXConnectClient()) { var xGenContact = new Contact(identifier); client.AddContact(xGenContact); var contactPersonalInfo = new PersonalInformation() { FirstName = Name.First(), LastName = Name.Last() }; client.SetFacet(xGenContact, PersonalInformation.DefaultFacetKey, contactPersonalInfo); var contactEmailAddresses = new EmailAddressList(new EmailAddress(Internet.Email($"{contactPersonalInfo.FirstName} {contactPersonalInfo.LastName}"), true), "Work"); client.SetFacet(xGenContact, EmailAddressList.DefaultFacetKey, contactEmailAddresses); client.Submit(); xGenContact = client.Get <Contact>(new IdentifiedContactReference(identifier.Source, identifier.Identifier), new ExpandOptions()); return(xGenContact); } }
public void SetContactData(string firstName, string lastName, string email) { IContactRepository repository = new XConnectContactRepository(); var contact = repository.GetCurrentContact(PersonalInformation.DefaultFacetKey); var personalInfo = contact.Personal(); if (personalInfo == null) { personalInfo = new PersonalInformation(); } personalInfo.FirstName = firstName; personalInfo.LastName = lastName; repository.SaveFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo); repository.ReloadCurrentContact(); contact = repository.GetCurrentContact(EmailAddressList.DefaultFacetKey); var emails = contact.Emails(); if (emails == null) { emails = new EmailAddressList(new EmailAddress(email, true), "default"); } emails.PreferredEmail = new EmailAddress(email, true); repository.SaveFacet(contact, EmailAddressList.DefaultFacetKey, emails); repository.ReloadCurrentContact(); }
public bool SetFacets(UserProfile profile, Contact contact, IXdbContext client) { var email = profile.Email; if (string.IsNullOrEmpty(email)) { return(false); } var emails = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); if (emails == null) { emails = new EmailAddressList(new EmailAddress(email, false), null); } else { if (emails.PreferredEmail?.SmtpAddress == email) { return(false); } emails.PreferredEmail = new EmailAddress(email, false); } client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emails); return(true); }
/// <summary> /// This function return's the email address of the current logged on user. /// If its email-address is not valid or not found, /// then the Default address is returned /// </summary> /// <param name="defaultEmail"> /// The default email. /// </param> /// <param name="validated"> /// if set to <c>true</c> [validated]. /// </param> /// <returns> /// Current user's email address. /// </returns> public static string GetCurrentUserEmailAddress(string defaultEmail, bool validated = true) { if (HttpContext.Current.User is WindowsPrincipal) { // windows user var eal = ADHelper.GetEmailAddresses(HttpContext.Current.User.Identity.Name); return(eal.Count == 0 ? defaultEmail : (string)eal[0]); } else { // Get the logged on email address from the context // string email = System.Web.HttpContext.Current.User.Identity.Name; var email = PortalSettings.CurrentUser.Identity.Email; if (!validated) { return(email); } // Check if its email address is valid var eal = new EmailAddressList(); try { eal.Add(email); return(email); } catch { return(defaultEmail); } } }
private bool SetEmail(ContactFacetData data, XConnect.Contact contact, XConnectClient client) { var email = data.EmailAddress; if (string.IsNullOrEmpty(email)) { return(false); } var emailFacet = new EmailAddressList(new EmailAddress(email, true), "Work Email"); client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emailFacet); return(true); }
protected void UpdateEmail(IIdentificationPayload data, Dictionary <string, Facet> facets) { EmailAddressList emails; if (facets.ContainsKey(EmailAddressList.DefaultFacetKey)) { emails = (EmailAddressList)facets[EmailAddressList.DefaultFacetKey]; emails.PreferredEmail = new EmailAddress(data.Email, true); } else { emails = new EmailAddressList(new EmailAddress(data.Email, true), Wellknown.PreferredEmailKey); facets.Add(EmailAddressList.DefaultFacetKey, emails); } }
private void SetEmailFacet() { var preferredKey = "Work"; var preferredEmail = new EmailAddress(CandidateContactInfo.EmailAddress, true); var emailFacet = new EmailAddressList(preferredEmail, preferredKey) { Others = new System.Collections.Generic.Dictionary <string, EmailAddress>() { { "Spam", new EmailAddress("*****@*****.**", false) } }, }; Client.SetFacet(new FacetReference(IdentifiedContactReference, EmailAddressList.DefaultFacetKey), emailFacet); }
public static void GetObjectPostAction(DataRow inputRow, DataTable table, DataObjectStore store) { DataRow dataRow = table.Rows[0]; if (dataRow["SimpleEmailAddresses"] != DBNull.Value) { dataRow["EmailAddresses"] = EmailAddressList.FromProxyAddressCollection((ProxyAddressCollection)dataRow["SimpleEmailAddresses"]); } if (dataRow["ObjectCountryOrRegion"] != DBNull.Value) { dataRow["CountryOrRegion"] = ((CountryInfo)dataRow["ObjectCountryOrRegion"]).Name; } MailboxPropertiesHelper.GetMaxSendReceiveSize(inputRow, table, store); MailboxPropertiesHelper.GetAcceptRejectSendersOrMembers(inputRow, table, store); }
public void SetEmail(string source, string identifier, string email) { using (XConnectClient client = GetClient()) { try { IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact contact = client.Get <Contact>( reference, new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey, EmailAddressList.DefaultFacetKey })); if (contact == null) { return; } EmailAddressList emails = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); var preferredEmail = new EmailAddress(email, true); if (emails == null) { emails = new EmailAddressList(preferredEmail, "Work"); } else { emails.PreferredEmail = preferredEmail; } client.SetEmails(contact, emails); client.Submit(); var operations = client.LastBatch; // Loop through operations and check status foreach (var operation in operations) { //Sitecore.Diagnostics.Log.Info(operation.OperationType + operation.Target.GetType().ToString() + " Operation: " + operation.Status, this); } } catch (XdbExecutionException ex) { //Sitecore.Diagnostics.Log.Error(ex.Message + ex.StackTrace, this); } } }
private static void UpdateEmailFacet(XConnectClient client, Contact contact) { var facet = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); if (facet != null) { facet.PreferredEmail = new EmailAddress(_fakeContact.EmailAddress, true); facet.PreferredKey = _fakeContact.PreferredEmailAddressKey; client.SetFacet(contact, EmailAddressList.DefaultFacetKey, facet); } else { EmailAddressList emails = new EmailAddressList(new EmailAddress(_fakeContact.EmailAddress, true), _fakeContact.PreferredEmailAddressKey); client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emails); } }
/// <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); } } }
public void RegisterUser(string email, double latitude, double longitude) { using (var client = SitecoreXConnectClientConfiguration.GetClient()) { { try { var contact = new Contact(new ContactIdentifier(IdSource, email, ContactIdentifierType.Known)); client.AddContact(contact); //email var emails = new EmailAddressList(new EmailAddress(email, true), "Home"); client.SetFacet(contact, emails); //geo location var homeAddress = new Address() { GeoCoordinate = new GeoCoordinate(latitude, longitude) }; AddressList addresses = new AddressList(homeAddress, "Home"); client.SetFacet(contact, AddressList.DefaultFacetKey, addresses); //register goal Guid channelId = Guid.Parse(DirectChannelId); string userAgent = HttpContext.Current?.Request?.UserAgent; var interaction = new Interaction(contact, InteractionInitiator.Brand, channelId, userAgent); var goal = new Goal(Guid.Parse(RegisterGoalId), DateTime.UtcNow); interaction.Events.Add(goal); client.AddInteraction(interaction); client.Submit(); //first load of air quality data UpdateAirQualityForContact(contact); } catch (XdbExecutionException ex) { Log.Error($"Error while registering a contact {email}", ex, this); throw ex; } } } }
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); }