private void CreateNewCrmAccount(ExigoContact eContact) { Contact cContact = new Contact(); cContact.New_PhoneSync = false; updater.CheckForUpdate(eContact, cContact); }
private void CheckCrmforContact(ExigoContact exigoContact) { if (CrmWithExigoIDs.Where(c => c.new_FREZZORID == exigoContact.ExigoID).Count() > 0) { var f = CrmWithExigoIDs.Where(c => c.new_FREZZORID == exigoContact.ExigoID).FirstOrDefault(); MatchInCRMFoundByID.Add(exigoContact, f); Settings.Logging.logger.LogData(Settings.Logging.AccountCheckingLog.Name, new List <string>() { exigoContact.ExigoID.ToString(), f.new_FREZZORID.ToString(), "True", f.Id.ToString(), exigoContact.FirstName, exigoContact.LastName, exigoContact.Email, f.FirstName, f.LastName, f.EMailAddress1 }); return; } else { var t = base.SearchForContact(exigoContact.FirstName, exigoContact.LastName, exigoContact.Email).FirstOrDefault(); if (t != null) { MatchInCRMFoundByInfo.Add(exigoContact, t); Settings.Logging.logger.LogData(Settings.Logging.AccountCheckingLog.Name, new List <string>() { exigoContact.ExigoID.ToString(), t.new_FREZZORID.ToString(), "True", t.Id.ToString(), exigoContact.FirstName, exigoContact.LastName, exigoContact.Email, t.FirstName, t.LastName, t.EMailAddress1 }); return; } } NoMatchInCRMFound.Add(exigoContact); Settings.Logging.logger.LogData(Settings.Logging.AccountCheckingLog.Name, new List <string>() { exigoContact.ExigoID.ToString(), "", "False", "", exigoContact.FirstName, exigoContact.LastName, exigoContact.Email, "", "", "" }); }
/// <summary> /// Here we are looking for an account in CRM using the GUID in Exigo if we find the Account /// by GUID we are adding to crmAccounts list if we cannot find the GUID we add the account to the /// ExigoRemoveGUIDs List. /// </summary> /// <param name="Econtact"></param> private void PopulateCrmAccounts(ExigoContact Econtact) { try { crmAccounts.Add(base.SearchForContact(Econtact.GetGUID())); } catch { ExigoRemoveGUIDs.Add(Econtact); } }
// delegate void GetAlias(ExigoContact contact); private void AssignAlias(ExigoContact contact) { if (contact.CustomerType == ExigoCustomerType.Independant) { try { contact.WebAlias = ExigoApiContext.CreateWebServiceContext().GetCustomerSite(new GetCustomerSiteRequest() { CustomerID = contact.ExigoID }).WebAlias; KnownWebAlais.Add(contact.ExigoID); } catch { } } }
private void FindAccountInCRM(ExigoContact contact) { if (CrmQ.FREZZORContactsinCRM.Where(c => c.new_FREZZORID == contact.ExigoID).Count() >= 1) { return; } var results = CrmQ.SearchForContact(contact.FirstName, contact.LastName, contact.Email); if (results.Count() > 0) { contact.CrmGuid = results.FirstOrDefault().Id.ToString(); AccountsFoundInCrm.Add(contact, results.FirstOrDefault()); } else { NewExigoAccounts.Add(contact); } }
private void ConvertResponseToModel() { if (ApiResponse.RecordCount > 0) { foreach (var resp in ApiResponse.Customers) { ExigoContact exigoContact = new ExigoContact() { ExigoID = resp.CustomerID, FirstName = resp.FirstName.Trim(), LastName = resp.LastName.Trim(), Gender = ExigoGenderType.Unknown, LastModified = resp.ModifiedDate, StartDate = resp.CreatedDate, Birthdate = resp.BirthDate, CrmGuid = resp.Field8, CustomerType = (ExigoCustomerType)resp.CustomerType, Status = (ExigoStatusTypes)resp.CustomerStatus, Email = resp.Email.Trim(), LangID = resp.LanguageID, Rank = resp.RankID, StreetAddress = resp.MainAddress1.Trim(), StreetAddress_Line2 = resp.MainAddress2.Trim(), City = resp.MainCity.Trim(), State = resp.MainState.Trim(), Zip = resp.MainZip.Trim(), Country = Utilities.ConvertCountryForCRM(resp.MainCountry), EnrollerID = resp.EnrollerID }; ExigoGenderType gender; if (Enum.TryParse(resp.Gender.ToString(), out gender)) { exigoContact.Gender = gender; } ; exigoContact.MobilePhone = (string.IsNullOrWhiteSpace(resp.MobilePhone)) ? string.Empty : resp.MobilePhone.FormatPhoneCRM(exigoContact.Country).Trim(); exigoContact.BusinessPhone = (string.IsNullOrWhiteSpace(resp.Phone)) ? string.Empty : resp.Phone.FormatPhoneCRM(exigoContact.Country).Trim(); exigoContact.HomePhone = (string.IsNullOrWhiteSpace(resp.Phone2)) ? string.Empty : resp.Phone2.FormatPhoneCRM(exigoContact.Country).Trim(); ContactList.Add(exigoContact); } ContactList.AsParallel().Where(c => c.CustomerType == ExigoCustomerType.Independant).AsParallel().ForAll(AssignAlias); ContactList.AsParallel().Where(c => c.CustomerType != ExigoCustomerType.Independant).AsParallel().ForAll(AssignEnrollerAlias); } }
private void AssignEnrollerAlias(ExigoContact contact) { if (KnownWebAlais.Contains(contact.EnrollerID)) { contact.EnrollerWebAlias = ContactList.Where(c => c.ExigoID == contact.EnrollerID).Select(c => c.WebAlias).FirstOrDefault(); } else { try { contact.EnrollerWebAlias = ExigoApiContext.CreateWebServiceContext().GetCustomerSite(new GetCustomerSiteRequest() { CustomerID = contact.EnrollerID }).WebAlias; } catch { } } }
private void LocateTermCrmAccount(ExigoContact eContact) { var crmAccountList = SearchForContact(eContact.GetGUID(), eContact.FirstName, eContact.LastName); if (crmAccountList.Count() > 0) { var crmAccount = crmAccountList.FirstOrDefault(); if (crmAccount.Id == eContact.GetGUID() && crmAccount.FirstName == eContact.FirstName && crmAccount.LastName == eContact.LastName) { crmContext.Update(new Contact() { Id = eContact.GetGUID(), New_Status = (int)eContact.Status, New_Type = (int)CrmCustomerType.Prospect }); } } ExigoApiContext.CreateWebServiceContext().UpdateCustomer(new ExigoDesktop.Exigo.WebService.UpdateCustomerRequest() { CustomerID = eContact.ExigoID, Field8 = string.Empty }); }
/// <summary> /// Comapares an Exigo Account and a CRM Account if account has changed returns CRM Account with only /// updates made on it. /// </summary> /// <param name="exigoContact"></param> /// <param name="crmContact"></param> public void CheckForUpdate(ExigoContact exigoContact, Contact crmContact) { var guid = crmContact.Id.ToString(); _currentAccountIsModified = false; _currentAccount = new Contact(); if (crmContact != null && crmContact.Id.ToString() != "00000000-0000-0000-0000-000000000000") { _currentAccount.Id = crmContact.Id; } if (!stringFieldMatch(exigoContact.FirstName, crmContact.FirstName, guid, FirstName, exigoContact.ExigoID)) { _currentAccount.FirstName = exigoContact.FirstName; } if (!stringFieldMatch(exigoContact.LastName, crmContact.LastName, guid, LastName, exigoContact.ExigoID)) { _currentAccount.LastName = exigoContact.LastName; } if (!string.IsNullOrEmpty(exigoContact.MobilePhone) && !stringFieldMatch(exigoContact.MobilePhone, crmContact.MobilePhone, guid, MobilePhone, exigoContact.ExigoID)) { _currentAccount.MobilePhone = exigoContact.MobilePhone; } if (!string.IsNullOrEmpty(exigoContact.BusinessPhone) && !stringFieldMatch(exigoContact.BusinessPhone, crmContact.Telephone1, guid, BusinessPhone, exigoContact.ExigoID)) { _currentAccount.Telephone1 = exigoContact.BusinessPhone; } if (!string.IsNullOrEmpty(exigoContact.HomePhone) && !stringFieldMatch(exigoContact.HomePhone, crmContact.Telephone2, guid, HomePhone, exigoContact.ExigoID)) { _currentAccount.Telephone2 = exigoContact.HomePhone; } if (!stringFieldMatch(exigoContact.StreetAddress, crmContact.Address1_Line1, guid, Address1Line1, exigoContact.ExigoID)) { _currentAccount.Address1_Line1 = exigoContact.StreetAddress; } if (!string.IsNullOrEmpty(exigoContact.StreetAddress_Line2) && !stringFieldMatch(exigoContact.StreetAddress_Line2, crmContact.Address1_Line2, guid, Address1Line2, exigoContact.ExigoID)) { _currentAccount.Address1_Line2 = exigoContact.StreetAddress_Line2; } if (!stringFieldMatch(exigoContact.City, crmContact.Address1_City, guid, Address1City, exigoContact.ExigoID)) { _currentAccount.Address1_City = exigoContact.City; } if (!stringFieldMatch(exigoContact.Zip, crmContact.Address1_PostalCode, guid, Address1ZipCode, exigoContact.ExigoID)) { _currentAccount.Address1_PostalCode = exigoContact.Zip; } if (!stringFieldMatch(exigoContact.Country, crmContact.Address1_Country, guid, Address1Country, exigoContact.ExigoID)) { _currentAccount.Address1_Country = exigoContact.Country; } /// checking nullable fields if (crmContact.new_FREZZORID == null) { _currentAccount.new_FREZZORID = exigoContact.ExigoID; UpdateNullField(guid, FrezzorID, exigoContact.ExigoID.ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch(exigoContact.ExigoID, (int)crmContact.new_FREZZORID, guid, FrezzorID, exigoContact.ExigoID)) { _currentAccount.new_FREZZORID = exigoContact.ExigoID; } } if (crmContact.new_EnrollerID == null) { _currentAccount.new_EnrollerID = exigoContact.EnrollerID; UpdateNullField(guid, EnrollerId, exigoContact.EnrollerID.ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch(exigoContact.EnrollerID, (int)crmContact.new_EnrollerID, guid, EnrollerId, exigoContact.ExigoID)) { _currentAccount.new_EnrollerID = exigoContact.EnrollerID; } } if (crmContact.new_FREZZOR_Language == null) { _currentAccount.new_FREZZOR_Language = exigoContact.LangID; UpdateNullField(guid, Language, exigoContact.LangID.ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch(exigoContact.LangID, (int)crmContact.new_FREZZOR_Language, guid, Language, exigoContact.ExigoID)) { _currentAccount.new_FREZZOR_Language = exigoContact.LangID; } } if (crmContact.New_Type == null) { _currentAccount.New_Type = (int)exigoContact.CustomerType; UpdateNullField(guid, FrezzorCustomerType, exigoContact.CustomerType.ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch((int)exigoContact.CustomerType, (int)crmContact.New_Type, guid, FrezzorCustomerType, exigoContact.ExigoID)) { _currentAccount.New_Type = (int)exigoContact.CustomerType; } } if (crmContact.New_Status == null) { _currentAccount.New_Status = (int)exigoContact.Status; UpdateNullField(guid, FrezzorStatus, Enum.GetName(exigoContact.Status.GetType(), (int)exigoContact.Status), exigoContact.ExigoID); } else { if (!intFieldMatch((int)exigoContact.Status, (int)crmContact.New_Status, guid, FrezzorStatus, exigoContact.ExigoID)) { _currentAccount.New_Status = (int)exigoContact.Status; } } /// before we change emails we must move email stored in email1 to email3 if (!stringFieldMatch(exigoContact.Email, crmContact.EMailAddress1, guid, Email, exigoContact.ExigoID)) { _currentAccount.EMailAddress3 = crmContact.EMailAddress1; _currentAccount.EMailAddress1 = exigoContact.Email; } if (exigoContact.GetBirthYear() != "1900" & exigoContact.GetBirthYear() != "1") { if (crmContact.New_BirthMonth.HasValue == false) { _currentAccount.New_BirthMonth = exigoContact.GetBirthMonth(); UpdateNullField(guid, MonthOfBirth, exigoContact.GetBirthMonth().ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch(exigoContact.GetBirthMonth(), (int)crmContact.New_BirthMonth, guid, MonthOfBirth, exigoContact.ExigoID)) { _currentAccount.New_BirthMonth = exigoContact.GetBirthMonth(); } } if (crmContact.New_BirthdayofMonth.HasValue == false) { _currentAccount.New_BirthdayofMonth = exigoContact.GetBirthDay(); UpdateNullField(guid, DayOfBirth.ToString(), exigoContact.GetBirthDay().ToString(), exigoContact.ExigoID); } else { if (!intFieldMatch(exigoContact.GetBirthDay(), (int)crmContact.New_BirthdayofMonth, guid, DayOfBirth, exigoContact.ExigoID)) { _currentAccount.New_BirthdayofMonth = exigoContact.GetBirthDay(); } } if (!stringFieldMatch(exigoContact.GetBirthYear(), (string)crmContact.New_BirthYear, guid, YearOfBirth, exigoContact.ExigoID)) { _currentAccount.New_BirthYear = exigoContact.GetBirthYear(); } } /// only update rank if rank in crm is less than current rank /// CRM only takes a rank of 1 or above, exigo ranks start a 0 /// to avoid throwing exception must not use rank of 0 if (crmContact.New_Rank == null) { if (exigoContact.Rank > 0) { _currentAccount.New_Rank = exigoContact.Rank; UpdateNullField(guid, Rank, exigoContact.Rank.ToString(), exigoContact.ExigoID); } } else { if (exigoContact.Rank > 0 && crmContact.New_Rank < exigoContact.Rank) { if (!intFieldMatch(exigoContact.Rank, (int)crmContact.New_Rank, guid, Rank, exigoContact.ExigoID)) { _currentAccount.New_Rank = exigoContact.Rank; } } } /// crm does not use states for countries other than US if (exigoContact.Country == "USA") { if (!stringFieldMatch(exigoContact.State, crmContact.Address1_StateOrProvince, guid, Address1State, exigoContact.ExigoID)) { _currentAccount.Address1_StateOrProvince = exigoContact.State; } } else { if (exigoContact.Country != "USA" & crmContact.Address1_StateOrProvince != null) { if (!stringFieldMatch(string.Empty, crmContact.Address1_StateOrProvince, guid, Address1State, exigoContact.ExigoID)) { _currentAccount.Address1_StateOrProvince = string.Empty; } } } if (crmContact.new_ExigoLastModifiedDate == null) { UpdateNullField(guid, FrezzorLastModDate, exigoContact.LastModified.ToString(), exigoContact.ExigoID); _currentAccount.new_ExigoLastModifiedDate = exigoContact.LastModified; } else { if (!stringFieldMatch(exigoContact.LastModified.AddHours(7).ToString(), crmContact.new_ExigoLastModifiedDate.ToString(), guid, FrezzorLastModDate, exigoContact.ExigoID)) { _currentAccount.new_ExigoLastModifiedDate = exigoContact.LastModified; } } /// if gender is unknown exigo contact model returns empty string if (!string.IsNullOrEmpty(exigoContact.Salutation)) { if (!stringFieldMatch(exigoContact.Salutation, crmContact.Salutation, guid, Salutation, exigoContact.ExigoID)) { _currentAccount.Salutation = exigoContact.Salutation; } } if (exigoContact.CustomerType == ExigoCustomerType.Independant) { if (!stringFieldMatch(exigoContact.WebAlias, crmContact.NickName, guid, WebAlias, exigoContact.ExigoID)) { _currentAccount.NickName = exigoContact.WebAlias; } } /// update enroller webalias if not distributor and enroller has webalias if (exigoContact.CustomerType != ExigoCustomerType.Independant && !string.IsNullOrEmpty(exigoContact.EnrollerWebAlias)) { if (!stringFieldMatch(exigoContact.EnrollerWebAlias, (string)crmContact.new_EnrollerWebAlias, guid, EnrollerWebAlias, exigoContact.ExigoID)) { _currentAccount.new_EnrollerWebAlias = exigoContact.EnrollerWebAlias; } } if (exigoContact.CustomerType != ExigoCustomerType.Independant && !string.IsNullOrEmpty(exigoContact.WebAlias)) { _currentAccount.NickName = string.Empty; } if (_currentAccountIsModified) { _changedAccounts.Add(_currentAccount); } }