private void ProcessContact(T data, IList <IViewModel> fields) { var contactIdentifier = GetContactIdentifier(data, fields); if (contactIdentifier == null) { throw new ContactIdentifierException(); } var marketingPreferencesViewModel = _saveMarketingPreferencesService.GetMarketingPreferencesViewModel(fields); if (marketingPreferencesViewModel == null) { throw new MarketingPreferencesException(); } var managerRoot = _saveMarketingPreferencesService.GetManagerRoot(marketingPreferencesViewModel); if (managerRoot == null) { throw new ManagerRootException(); } var listId = ParseContactListId(marketingPreferencesViewModel); if (!listId.HasValue) { throw new ContactListException(); } var contact = GetXConnectContactByIdentifer(contactIdentifier); if (contact != null) { if (IsContactSubscribedToList(contact, listId.Value)) { if (!_saveMarketingPreferencesService.AuthenticateContact(contact)) { throw new ContactIdentifierException(); } var marketingPreferences = _saveMarketingPreferencesService.GetSelectedMarketingPreferences(marketingPreferencesViewModel, managerRoot, contact.ExmKeyBehaviorCache()?.MarketingPreferences).ToList(); _marketingPreferenceService.SavePreferences(contact, marketingPreferences); return; } } var customXConnectContact = _xConnectContactFactory.CreateContactWithEmail(contactIdentifier.Identifier); _xConnectContactService.IdentifyCurrent(customXConnectContact); _xConnectContactService.UpdateOrCreateContact(customXConnectContact); var newContact = GetXConnectContactByIdentifer(contactIdentifier); if (newContact == null) { throw new ContactException(); } _saveMarketingPreferencesService.SetPersonalInformation(data, fields, newContact, contactIdentifier); _saveMarketingPreferencesService.SetExmKeyBehaviorCache(newContact); var newMarketingPreferences = _saveMarketingPreferencesService.GetSelectedMarketingPreferences(marketingPreferencesViewModel, managerRoot, newContact.ExmKeyBehaviorCache()?.MarketingPreferences).ToList(); if (newMarketingPreferences.All(x => x.Preference == false)) { UnsubscribeFromAll(contactIdentifier, managerRoot); return; } SubscribeContact(managerRoot, listId.Value, contactIdentifier, newMarketingPreferences); }
public List <MarketingPreference> SavePreferences(Contact contact, List <MarketingPreference> preferences) { return(_marketingPreferencesService.SavePreferences(contact, preferences)); }