示例#1
0
        public void AddPropertiesToContact(Contact contactToUpdate, ProductAnalyticData productAnalyticForContact)
        {
            var contactSearchPhrase = productAnalyticForContact.ContactSearchPhrase;
            var contactSource       = productAnalyticForContact.ContactSource;
            var contactMedium       = productAnalyticForContact.ContactMedium;
            var contactCampaign     = productAnalyticForContact.ContactCampaign;

            if (IsPropertyValid(contactCampaign))
            {
                contactToUpdate.Campaign = contactCampaign;
            }
            if (IsPropertyValid(contactSearchPhrase))
            {
                contactToUpdate.SearchPhrase = contactSearchPhrase;
            }
            if (IsPropertyValid(contactSource))
            {
                contactToUpdate.Source = contactSource;
            }
            if (IsPropertyValid(contactMedium))
            {
                contactToUpdate.Medium = contactMedium;
            }

            if (contactProductService.IsValidProduct(contactCampaign, contactMedium))
            {
                var product = contactProductService.GetProduct(contactCampaign, contactMedium);
                contactToUpdate.Product = product;
            }


            contactRepository.SaveChanges();
        }
示例#2
0
        public void SetContactPropertiesForAnalyticData(ProductAnalyticData productAnalyticForContact)
        {
            var contactAction   = productAnalyticForContact.ContactAction;
            var contactLabel    = productAnalyticForContact.ContactLabel;
            var contactCategory = productAnalyticForContact.ContactCategory;

            if (contactCategory.Equals("Calls"))
            {
                var apiAccessId = contactLabel.Split(',')[2];
                if (apiAccessId == null)
                {
                    throw new Exception("No CTM Api Access Id Found");
                }

                var matchingContactForUpdateCredentials =
                    contactRepository.Where(l => l.Property.Any(lp => lp.Type == "CTMId" && lp.Value == apiAccessId.Trim()));

                if (matchingContactForUpdateCredentials.Any())
                {
                    var contactToUpdate = matchingContactForUpdateCredentials.Single();
                    AddPropertiesToContact(contactToUpdate, productAnalyticForContact);
                }
            }
            else if (contactCategory == "HelloyContact")
            {
                if (contactAction == "Mail")
                {
                    dynamic apiAccessIdLabel = JsonConvert.DeserializeObject(contactLabel);
                    string  apiAccessId      = apiAccessIdLabel.mandrillId;

                    if (apiAccessId == null)
                    {
                        throw new Exception("No Mandrill Api Access Id Found");
                    }
                    var matchingContactForUpdateCredentials =
                        contactRepository.Where(l => l.Property.Any(lp => lp.Type == "MandrillId" && lp.Value == apiAccessId.Trim()));

                    if (matchingContactForUpdateCredentials.Any())
                    {
                        var contactToUpdate = matchingContactForUpdateCredentials.Single();
                        AddPropertiesToContact(contactToUpdate, productAnalyticForContact);
                    }
                }
                else if (contactAction == "Chat")
                {
                    dynamic apiAccessIdLabel = JsonConvert.DeserializeObject(contactLabel);
                    string  apiAccessId      = apiAccessIdLabel.chat_id;

                    if (apiAccessId == null)
                    {
                        throw new Exception("No LiveChat Api Access Id Found");
                    }
                    var matchingContactForUpdateCredentials =
                        contactRepository.Where(l => l.Property.Any(lp => lp.Type == "LiveChatId" && lp.Value == apiAccessId.Trim()));

                    if (matchingContactForUpdateCredentials.Any())
                    {
                        var contactToUpdate = matchingContactForUpdateCredentials.Single();
                        AddPropertiesToContact(contactToUpdate, productAnalyticForContact);
                    }
                }
                else if (contactAction == "Form")
                {
                    dynamic apiAccessIdLabel = JsonConvert.DeserializeObject(contactLabel);
                    string  apiAccessId      = apiAccessIdLabel.formPostId;

                    if (apiAccessId == null)
                    {
                        throw new Exception("No Form Access Id Found");
                    }
                    var matchingContactForUpdateCredentials =
                        contactRepository.Where(l => l.Property.Any(lp => lp.Type == "FormPostId" && lp.Value == apiAccessId.Trim()));

                    if (matchingContactForUpdateCredentials.Any())
                    {
                        var contactToUpdate = matchingContactForUpdateCredentials.Single();
                        AddPropertiesToContact(contactToUpdate, productAnalyticForContact);
                    }
                }
            }
        }