public void UpdateSubscriber(string token, BulkEmailSubscriber subscriber) { var subscriberDictionary = new Dictionary<string, object> { {"Contact_Publication_ID", subscriber.ContactPublicationId}, {"Unsubscribed", !subscriber.Subscribed}, {"Third_Party_Contact_ID", subscriber.ThirdPartyContactId} }; _ministryPlatformService.UpdateRecord(Convert.ToInt32(AppSettings("Subscribers")), subscriberDictionary, token); }
private SubscriberOperationDTO GetOperation(BulkEmailPublication publication, BulkEmailSubscriber subscriber) { var mailChimpSubscriber = new SubscriberDTO(); mailChimpSubscriber.Subscribed = subscriber.Subscribed; mailChimpSubscriber.EmailAddress = subscriber.ThirdPartyContactId; mailChimpSubscriber.MergeFields = subscriber.MergeFields; var hashedEmail = CalculateMD5Hash(mailChimpSubscriber.EmailAddress.ToLower()); var operation = new SubscriberOperationDTO(); operation.Method = "PUT"; operation.Path = string.Format("lists/{0}/members/{1}", publication.ThirdPartyPublicationId, hashedEmail); // TODO: Do we need to store this somewhere to verify subscriber processed successfully operation.OperationId = Guid.NewGuid().ToString(); operation.Body = JsonConvert.SerializeObject(mailChimpSubscriber); return operation; }
private SubscriberOperationDTO UnsubscribeOldEmailAddress(BulkEmailPublication publication, BulkEmailSubscriber subscriber) { var updatedSubcriber = subscriber.Clone(); updatedSubcriber.Subscribed = false; var updateOperation = GetOperation(publication, updatedSubcriber); return updateOperation; }
private Dictionary<int, BulkEmailSubscriber> GetBaseSubscribers(string token, string publicationFilter) { var records = _ministryPlatformService.GetPageViewRecords(_segmentationBasePageViewId, token, publicationFilter); var subscribers = new Dictionary<int, BulkEmailSubscriber>(); foreach (var record in records) { var subscriber = new BulkEmailSubscriber(); subscriber.ContactPublicationId = record.ToInt("Contact_Publication_ID"); subscriber.ContactId = record.ToInt("Contact_ID"); subscriber.EmailAddress = record.ToString("Email_Address"); subscriber.ThirdPartyContactId = record.ToString("Third_Party_Contact_ID"); subscriber.Subscribed = !record.ToBool("Unsubscribed"); AddMergeFields(subscriber, record); subscribers.Add(subscriber.ContactPublicationId, subscriber); } return subscribers; }
private void AddMergeFields(BulkEmailSubscriber subscriber, Dictionary<string, object> record) { var columnsToSkip = new List<string>() { "dp_RecordID", "dp_RecordName", "dp_Selected", "dp_FileID", "dp_RecordStatus", "Contact_Publication_ID", "Publication_ID", "Title", "Third_Party_Publication_ID", "Last_Successful_Sync", "Unsubscribed", "Third_Party_Contact_ID", "Contact_ID", "Email_Address" }; foreach (var column in record) { if (columnsToSkip.Contains(column.Key)) { continue; } if (subscriber.MergeFields.Keys.Contains(column.Key)) { continue; } if (column.Value == null) { continue; } subscriber.MergeFields.Add(column.Key, column.Value.ToString()); } }