Skip to content

Instantly share code, notes, and snippets.

@markgibbons25
Last active May 15, 2019 04:44
Show Gist options
  • Save markgibbons25/54162f81b141418af69962c431ab6484 to your computer and use it in GitHub Desktop.
Save markgibbons25/54162f81b141418af69962c431ab6484 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using Sitecore.Modules.EmailCampaign.Application.EmailDispatch;
namespace Foundation.xDB.sitecore.admin
{
public partial class ExmMessageActivator : System.Web.UI.Page
{
private IEmailDispatch _emailDispatch;
private const string EmailXpath = "/sitecore/content/Email//*[@@templateid='{078D8A76-F971-4891-B422-76C0BCF9FA03}']";
public ExmMessageActivator()
{
_emailDispatch = Sitecore.Modules.EmailCampaign.Application.Application.Instance.EmailDispatch;
}
protected void btnActivate_Click(object sender, EventArgs e)
{
var items = GetItems(false);
foreach (var item in items)
{
_emailDispatch.Activate(item);
}
}
protected void btnDeactivate_Click(object sender, EventArgs e)
{
var items = GetItems(true);
foreach (var item in items)
{
_emailDispatch.Deactivate(item);
}
}
private List<Guid> GetItems(bool isReadOnly)
{
return Sitecore.Data.Database.GetDatabase("master")
.SelectItems(EmailXpath)
.Where(x => x.Appearance.ReadOnly == isReadOnly)
.Select(x => x.ID.Guid)
.ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment