Create issues

To create an issue, you must use the NewslettersManager class. The following code creates an issue through the Native API.

Figure 1: Create an issue

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Newsletters;
using Telerik.Sitefinity.Newsletters.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.EmailCampaigns
{
    public partial class EmailCampaignsSnippets
    {
        public void CreateIssue(string campaignName, Guid issueId, Guid bodyId, string issueName, string fromName, string subject, string replyToMail)
        {
            NewslettersManager newslettersManager = NewslettersManager.GetManager();

            //create new campaign
            Campaign campaign = newslettersManager.CreateCampaign(true);
            campaign.Name = campaignName;
            newslettersManager.SaveChanges();

            if (campaign != null)
            {
                Campaign issue = newslettersManager.GetIssues().Where(a => a.Id == issueId).SingleOrDefault();

                //create new issue for the campaign
                if (issue == null)
                {
                    issue = newslettersManager.CreateIssue(campaign, true, issueId);
                    issue.MessageBody = newslettersManager.GetMessageBodies().Where(b => b.Id == bodyId).SingleOrDefault();
                    issue.Name = issueName;
                    issue.FromName = fromName;
                    issue.MessageSubject = subject;
                    issue.ReplyToEmail = replyToMail;
                    newslettersManager.SaveChanges();
                }
            }
        }
    }
}

First, you initialize the NewslettersManager. When creating an issue, you must provide a root campaign by instance or id. You create the root campaign, see Create campaigns. Next you call CreateIssue method to create the issue. Finally, after all properties are set, you save the changes.

NOTE: To create an issue with auto generated ID, use the other overload of the CreateIssue method.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?