// Set the properties newSubscriber.SubscriberFirstName = "Name"; newSubscriber.SubscriberLastName = "Surname"; newSubscriber.SubscriberFullName = "Name Surname"; newSubscriber.SubscriberEmail = "subscriber@localhost.local"; newSubscriber.SubscriberSiteID = CMSContext.CurrentSiteID;
// Save the subscriber SubscriberProvider.SetSubscriber(newSubscriber);
returntrue; }
The following example gets and updates a subscriber.
privatebool GetAndUpdateSubscriber() { // Get the subscriber Subscriber updateSubscriber = SubscriberProvider.GetSubscriber("subscriber@localhost.local", CMSContext.CurrentSiteID); if (updateSubscriber != null) { // Update the properties updateSubscriber.SubscriberFullName = updateSubscriber.SubscriberFullName.ToLower();
// Save the changes SubscriberProvider.SetSubscriber(updateSubscriber);
returntrue; }
returnfalse; }
The following example gets and bulk updates subscribers.
privatebool GetAndBulkUpdateSubscribers() { // Prepare the parameters string where = "SubscriberEmail LIKE N'subscriber@localhost.local%'";
// Get the data DataSet subscribers = SubscriberProvider.GetSubscribers(where, null); if (!DataHelper.DataSourceIsEmpty(subscribers)) { // Loop through the individual items foreach (DataRow subscriberDr in subscribers.Tables[0].Rows) { // Create object from DataRow Subscriber modifySubscriber = newSubscriber(subscriberDr);
// Update the properties modifySubscriber.SubscriberFullName = modifySubscriber.SubscriberFullName.ToUpper();
// Save the changes SubscriberProvider.SetSubscriber(modifySubscriber); }
returntrue; }
returnfalse; }
The following example subscribes a subscriber to newsletter.
privatebool SubscribeToNewsletter() { // Get the subscriber and newsletter Subscriber subscriber = SubscriberProvider.GetSubscriber("subscriber@localhost.local", CMSContext.CurrentSiteID); Newsletter newsletter = NewsletterProvider.GetNewsletter("MyNewStaticNewsletter", CMSContext.CurrentSiteID);
if ((subscriber != null) && (newsletter != null)) { // Subscribe to 'My new static newsletter' SubscriberProvider.Subscribe(subscriber.SubscriberID, newsletter.NewsletterID, DateTime.Now);
returntrue; }
returnfalse; }
The following example unsubscribes a subscriber from newsletter.
privatebool UnsubscribeFromNewsletter() { // Get the subscriber and newsletter Subscriber subscriber = SubscriberProvider.GetSubscriber("subscriber@localhost.local", CMSContext.CurrentSiteID); Newsletter newsletter = NewsletterProvider.GetNewsletter("MyNewStaticNewsletter", CMSContext.CurrentSiteID);
if ((subscriber != null) && (newsletter != null)) { // Unubscribe from 'My new static newsletter' SubscriberProvider.Unsubscribe(subscriber.SubscriberID, newsletter.NewsletterID);
returntrue; }
returnfalse; }
The following example deletes a subscriber.
privatebool DeleteSubscriber() { // Get the subscriber Subscriber deleteSubscriber = SubscriberProvider.GetSubscriber("subscriber@localhost.local", CMSContext.CurrentSiteID);
// Delete the subscriber SubscriberProvider.DeleteSubscriber(deleteSubscriber);