More in this section

Newsletter

2 posts, 0 answered
  1. rmoynihan
    rmoynihan avatar
    18 posts
    Registered:
    28 May 2007
    28 Sep 2008
    Link to this post
    Hi,

    I am creating a page which contains a checkbox which the user can tick to subscribe for the newsletter. How do I add the user to a newsltter group using the api.

    Thanks,

    Ronan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Oct 2008
    Link to this post
    Hello Ronan,

    Thank you for contacting us.

    Newsletter API is described in our Developer Manaual. Also, we have prepared a simple example for you that illustrates how to achieve the desired implementation:

    using System; 
    using System.Collections; 
    using System.Web.Security; 
    using Telerik.Newsletters; 
    using Telerik.Notifications.Newsletters; 
     
    namespace Custom 
        public class NewsletterHelper 
        { 
            /// <summary> 
            ///  
            /// </summary> 
            /// <param name="newsletterID">The ID of the newsletter you want to subscribe the current user to</param> 
            public void SubscribeCurrentUserToNewsletter(Guid newsletterID) 
            { 
                // Get a MembershipUser object of the currently logged-on user 
                MembershipUser user = Membership.GetUser(); 
                if (user != null
                { 
                    // Create an instance of Newsletter manager 
                    DataManager manager = new DataManager(); 
     
                    // Get the ISubscriber object by user email  
                    ISubscriber subscriber = manager.GetSubscriber(user.Email); 
                    if (subscriber == null
                    { 
                        // Create the subscriber if he/she does exists 
                        subscriber = manager.CreateSubscriber(user.Email); 
                        manager.SaveSubscriber(subscriber); 
                    } 
     
                    // Get the collection of the Newsletter groups 
                    IList groups = manager.GetGroupOfNewsletter(newsletterID); 
                     
                    IGroup group = null
     
                    // For example we need the first group in the collection 
                    if (groups.Count > 0) 
                        group = (IGroup)groups[0]; 
     
                    if (group != null
                    { 
                        // Subscribe the user to the group and save 
                        IGroupSubscriber groupSubscriber = manager.CreateGroupSubscriberRelation(group.GroupId, subscriber.SubscriberId); 
                        manager.SaveGroupSubscribers(groupSubscriber); 
                    } 
                } 
            } 
        } 

    Hope this helps.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered