using System.Web.Mvc; using Newtonsoft.Json; using Orchard; using Orchard.Data; using Orchard.Email.Models; using Orchard.Localization; using Orchard.Security; using Orchard.UI.Admin; using Orchard.UI.Notify; using Orchard.Workflows.Models; using Upgrade.Services; namespace Upgrade.Controllers { [Admin] public class MessagingController : Controller { private readonly IUpgradeService _upgradeService; private readonly IOrchardServices _orchardServices; private readonly IRepository _repository; public MessagingController( IUpgradeService upgradeService, IOrchardServices orchardServices, IRepository repository) { _upgradeService = upgradeService; _orchardServices = orchardServices; _repository = repository; } public Localizer T { get; set; } public ActionResult Index() { var found = false; _upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Workflows_ActivityRecord") + " WHERE Name = 'SendEmail'", (reader, connection) => { found = true; }); if (!found) { _orchardServices.Notifier.Warning(T("This step is unnecessary as no Send Email activities were found.")); } return View(); } [HttpPost, ActionName("Index")] public ActionResult IndexPOST() { if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to upgrade."))) return new HttpUnauthorizedResult(); _upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Workflows_ActivityRecord") + " WHERE Name = 'SendEmail'", (reader, connection) => { var record = _repository.Get((int) reader["Id"]); if (record == null) { return; } var state = JsonConvert.DeserializeAnonymousType(record.State, new { Body = "", Subject = "", Recipient = "", RecipientOther = "", }); var newState = new EmailMessage { Body = state.Body, Subject = state.Subject }; if (!newState.Body.StartsWith("