/// <summary> /// Add Interaction /// </summary> /// <param name="identifier">Email</param> /// <param name="googleApiFacetInfo"></param> public void RegisterInteraction(string identifier, GoogleApiFacetInfo googleApiFacetInfo) { using (XConnectClient client = GetClient()) { var contactReference = new IdentifiedContactReference(Constans.xConnectApiSource, identifier); var contact = client.Get <Contact>(contactReference, new ContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey })); if (contact == null) { return; } Interaction interaction = new Interaction(contactReference, InteractionInitiator.Contact, channelId: new Guid(Constans.Offline_OtherEventChannelId), userAgent: Constans.UserAgent); // Add Custom GoogleApiFacet GoogleApiFacet googleApiFacet = contact.GetFacet <GoogleApiFacet>(GoogleApiFacet.FacetName); if (googleApiFacet == null) { googleApiFacet = new GoogleApiFacet(); googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } else { googleApiFacet.GoogleApiFacetInfoList.Add(new GoogleApiFacetInfo { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } client.SetFacet <GoogleApiFacet>(new FacetReference(contact, GoogleApiFacet.FacetName), googleApiFacet); //// Adding some face information //IpInfo ipInfo = new IpInfo("127.0.0.1"); //ipInfo.BusinessName = "Home"; //client.SetFacet<IpInfo>(interaction, IpInfo.DefaultFacetKey, ipInfo); //WebVisit webVisit = new WebVisit(); //webVisit.SiteName = "Offline"; //client.SetFacet<WebVisit>(interaction, WebVisit.DefaultFacetKey, webVisit); Outcome outcome = new Outcome(new Guid(Constans.Offline_OtherEventChannelId), DateTime.UtcNow, "USD", 0) { EngagementValue = 10, Text = "Google Api Interaction" }; interaction.Events.Add(outcome); client.AddInteraction(interaction); client.Submit(); } }
/// <summary> /// Get Contact /// </summary> /// <param name="identifier">Email</param> /// <returns></returns> public ContactModel GetContact(string identifier) { ContactModel result = null; using (XConnectClient client = GetClient()) { var contactReference = new IdentifiedContactReference(Constans.xConnectApiSource, identifier); // Note: Make sure to pass the required facets, if not sure then pass all facets. var contactFacets = client.Model.Facets.Where(c => c.Target == EntityType.Contact).Select(x => x.Name); var contact = client.Get <Contact>(contactReference, new ContactExpandOptions(contactFacets.ToArray())); if (contact == null) { return(result); } PersonalInformation personalInformation = contact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (personalInformation == null) { return(result); } result = new ContactModel { FirstName = personalInformation.FirstName, LastName = personalInformation.LastName }; GoogleApiFacet googleApiFacet = contact.GetFacet <GoogleApiFacet>(GoogleApiFacet.FacetName); if (googleApiFacet != null) { result.GoogleInteractions = new List <GoogleInteractionModel>(); foreach (var googleApiFacetInfo in googleApiFacet.GoogleApiFacetInfoList) { result.GoogleInteractions.Add(new GoogleInteractionModel { ZipCode = googleApiFacetInfo.ZipCode, RestaurantType = googleApiFacetInfo.RestaurantType }); } } return(result); } }