Add cancel
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Hangfire;
|
||||
using log4net;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Utility;
|
||||
using LeafWeb.WebCms.App_Start;
|
||||
using LeafWeb.WebCms.Models;
|
||||
using LeafWeb.WebCms.Services;
|
||||
using LeafWeb.WebCms.Services.PiscalQueue;
|
||||
@@ -18,7 +20,7 @@ namespace LeafWeb.WebCms.Controllers
|
||||
DataService.GetLeafInputs()
|
||||
.OrderByDescending(f => f.Id)
|
||||
.ToList()
|
||||
.Select(leafInput => new ResultItemViewModel(leafInput));
|
||||
.Select(leafInput => new QueueItemViewModel(leafInput));
|
||||
|
||||
string serviceDescription;
|
||||
try
|
||||
@@ -121,6 +123,42 @@ namespace LeafWeb.WebCms.Controllers
|
||||
return RedirectToUmbracoPage(LeafWebPageIds.ManageQueue);
|
||||
}
|
||||
|
||||
[ActionLog]
|
||||
public ActionResult Cancel(int id)
|
||||
{
|
||||
var leafInput = DataService.GetLeafInput(id);
|
||||
|
||||
if (leafInput == null)
|
||||
{
|
||||
SetStatusMessage($"LeafInput '${id}' not found, may have been deleted?");
|
||||
return RedirectToUmbracoPage(LeafWebPageIds.ManageQueue);
|
||||
}
|
||||
|
||||
if (leafInput.IsPending)
|
||||
{
|
||||
LogManager.GetLogger(LoggerName(RouteData)).DebugFormat("LeafInput: {0}, Set Cancelled from Pending", leafInput.Id);
|
||||
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Cancelled,
|
||||
"Emailing cancellation notification to user",
|
||||
$"Email: \'{leafInput.Email}\'");
|
||||
|
||||
// send notification immediately
|
||||
BackgroundJob.Enqueue<EmailNotificationService>(email => email.SendLeafWebCancelled(leafInput.Id));
|
||||
SetStatusMessage($"Cancelling LeafInput '{leafInput.Identifier}'", StatusType.Success);
|
||||
}
|
||||
else if (leafInput.IsRunning)
|
||||
{
|
||||
DataService.SetLeafInputStatus(leafInput, LeafInputStatusType.CancelPending);
|
||||
SetStatusMessage($"Cancelling LeafInput '{leafInput.Identifier}'", StatusType.Success);
|
||||
HangfireStartup.TriggerPiscalProcessQueue();
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't allow to be cancelled if it isn't currently running
|
||||
SetStatusMessage($"LeafInput '{leafInput.Identifier}' is not currently running!", StatusType.Error);
|
||||
}
|
||||
return RedirectToCurrentUmbracoUrl();
|
||||
}
|
||||
|
||||
[ActionLog]
|
||||
public ActionResult SendUserDownloadLink(int id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user