1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Binding to Newsletter sent event

Binding to Newsletter sent event

6 posts, 0 answered
  1. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    01 Sep 2009
    Link to this post
    Hello,

    A client has requested that all of the newsletters sent from the newsletter module appear as threads in the forum, so that users can access them at any time, as well as post comments and have discussions about them. I assume that I will need to add the code to convert the newsletter into a forum thread at the sent method, but I'm not sure how to go about it and where to find it.

    Thank you for your support,

    David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Sep 2009
    Link to this post
    Hi David,

    Below is the code that you can use to accomplish your task.

             DataManager dManager = new DataManager(); 
            IList allLetters = dManager.GetNewsletters(); 
     
            ForumManager fManager = new ForumManager(); 
            Telerik.Forums.ICategory cat = fManager.CreateCategory("NewsletterPosts"); 
            Guid catID = Guid.NewGuid(); 
            cat.ID = catID; 
            fManager.SaveCategory(cat); 
            cat = fManager.GetCategory(catID); 
            IForum newForum = fManager.CreateForum(cat.ID, "NewsletterForum"falsefalse, ForumStatus.Visible); 
            Guid forumID = Guid.NewGuid(); 
            newForum.ID = forumID; 
            fManager.SaveForum(newForum); 
            newForum = fManager.GetForum(forumID); 
     
            IPost post = fManager.CreatePost(); 
            post.Content = "Thread content"
            post.Owner = "admin"
            Guid postID = Guid.NewGuid(); 
            post.ID = postID; 
            post.ForumID = newForum; 
            fManager.SavePost(post); 
            post = fManager.GetPost(postID); 
     
            foreach (INewsletter singleLetter in allLetters) 
            { 
                string letterSubject = singleLetter.Subject.ToString(); 
                string letterContent = singleLetter.Content.ToString(); 
                string letterSenderName = singleLetter.SenderName.ToString(); 
     
                IPost newPost = fManager.CreatePost(postID); 
                newPost.Owner = letterSenderName; 
                newPost.Content = letterContent; 
                newPost.Title = letterSubject; 
                newPost.ForumID = newForum; 
                newPost.Thread = post; 
                fManager.SavePost(newPost); 
             }


    Kind regards,
    Ivan Dimitrov
    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.
  3. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    02 Sep 2009
    Link to this post
    Thank you for your support.

    I was thinking along the same lines as the code you sent to implement this functionality, but wouldn't this code create a thread for each newsletter every time that the script was run? (Which would create duplicates) I was hoping that it would be possible to add some code to the event when a newsletter is sent, which would add a new thread to the existing Newsletter forum.

    I suppose if this is not possible, then it would be easy enough to add fManager.DeleteForum("Newsletters") to the code you provided so that a forum is deleted before its replacement is added. Would doing this, however, delete all existing posts in the forum, or would they linger in the database afterward and require additional code to remove?

    Thank you,

    David
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Sep 2009
    Link to this post
    Hi David,

    I am not sure whether you have tried the code, but it is working a bit different. The code gets all newsletters. We are creating a new category for our forum and then a new forum called - NewsletterForum. Afterwards we add a new thread. As you can see this is outside of our loop so this forum will be created only once.
    In a foreach loop where we are adding all the current newsletters as different posts. However you could access "sendTopbtn" LinkButton control under ~/Sitefinity/Admin/ControlTemplates/Notifications/NewsletterPreview.ascx. You can subscribe for button click and add the logic from the previous post by getting only the current newsletter and creating only one post. The forum should be created before that through Sitefinity's UI or programmatically. The logic is the same.

    I  hope this helps.

    All the best,
    Ivan Dimitrov
    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.
  5. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    03 Sep 2009
    Link to this post
    Thank you for your support.

    I guess I may be a little confused... I would like to put the above code in Global.asax. Is this the right code to create the event handler?
    Telerik.Notifications.Newsletters.DataManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(DataManager_Executed); 


    And then in DataManager_Executed, is there a commandName for the ExecutedEventArgs that I can use to make sure the newsletter is being sent? (for example)
    void DataManager_Executed(object sender, Telerik.ExecutedEventArgs e) 
       if (e.CommandName=="SendNewsletter"
       { 
         //Code goes here 
       } 


    Or, if I'm on the completely wrong track, I'd appreciate it if you could lead me down the right one.

    Thanks!

    David
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Sep 2009
    Link to this post
    Hi David,

    There is no event that you can use in global asax. We use Telerik.Notifications.Newsletters.SendEmail method, which is also static and MailingServiceProxy.

    All the best,
    Ivan Dimitrov
    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.
Register for webinar
6 posts, 0 answered