More in this section

Forums / Developing with Sitefinity / Newsletter group

Newsletter group

5 posts, 1 answered
  1. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    13 Dec 2009
    Link to this post
    Hi,
     How to add Newsletter group using API?

    thanks
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Dec 2009
    Link to this post
    Hello Rabindra,

    Thank you for using our services.

    Can you try with the following code snippet:
    DataManager newslettersManager = new DataManager();
    IGroup newGroup = newslettersManager.CreateGroup();
    newGroup.GroupName="New Group";
    //now lets say that you have Role1 and we will get all users from this role and put them in the group
    string[] userNames = Telerik.Security.UserManager.Default.GetUsersInRole("Role1");
    foreach(string userName in userNames)
    {
        System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(userName);
        ISubscriber subsciber = newslettersManager.CreateSubscriber(user.Email);
        ProfileBase profile = ProfileBase.Create(user.UserName);
        subsciber.LastName = profile.GetPropertyValue("LastName").ToString();
        subsciber.Name = profile.GetPropertyValue("FirestName").ToString();
        subsciber.Groups.Add(newGroup);
        newslettersManager.SaveSubscriber(subsciber);
    }
    newslettersManager.SaveGroup(newGroup);


    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    15 Dec 2009
    Link to this post
    Hi Radoslav ,
    I just needed first three lines.
    Worked great ..thanks
  4. Ales Tepina
    Ales Tepina avatar
    10 posts
    Registered:
    07 Dec 2009
    29 Apr 2010
    Link to this post
    I have a problem when trying to add a subscriber to a group

    DataManager dataManager = new DataManager("Newsletters");
    Telerik.Newsletters.ISubscriber subscriber = dataManager.CreateSubscriber(email);
     
    foreach (var subscriberGroupGuid in _subscriberGroupsGuids)
    {
       var group = dataManager.GetGroup(subscriberGroupGuid);
       subscriber.Groups.Add(group);
    }
    dataManager.SaveSubscriber(subscriber);

    I'm getting the error: The value "Telerik.Notifications.Data.Group" is not of type "Telerik.Notifications.Data.GroupSubscriber" and cannot be used in this generic collection.
  5. Ales Tepina
    Ales Tepina avatar
    10 posts
    Registered:
    07 Dec 2009
    29 Apr 2010
    Link to this post
    I solved the problem...here's how, if anyone will have a similar problem:

    DataManager dataManager = new DataManager("Newsletters");
     
    Telerik.Newsletters.ISubscriber subscriber = dataManager.CreateSubscriber(email);
    dataManager.SaveSubscriber(subscriber);
     
    foreach (var subscriberGroupGuid in _subscriberGroupsGuids)
    {
         IGroupSubscriber groupSubscriberRelation = DataManager.CreateGroupSubscriberRelation(subscriberGroupGuid, subscriber.SubscriberId);
         dataManager.SaveGroupSubscribers(groupSubscriberRelation);
    }
    dataManager.SaveSubscriber(subscriber);

Register for webinar
5 posts, 1 answered