Add cancel
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using log4net;
|
||||
using LeafWeb.Core.DAL;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -21,9 +22,7 @@ namespace LeafWeb.WebCms.Controllers
|
||||
{
|
||||
if (filterContext?.Exception != null)
|
||||
{
|
||||
var controller = filterContext.RouteData.Values["controller"].ToString();
|
||||
var action = filterContext.RouteData.Values["action"].ToString();
|
||||
var loggerName = $"LeafWeb.WebCms.Controllers.{controller}Controller.{action}";
|
||||
var loggerName = LoggerName(filterContext.RouteData);
|
||||
|
||||
LogManager.GetLogger(loggerName).Error(filterContext.Exception);
|
||||
}
|
||||
@@ -31,12 +30,14 @@ namespace LeafWeb.WebCms.Controllers
|
||||
base.OnException(filterContext);
|
||||
}
|
||||
|
||||
protected bool IsHttpParamActionMatch()
|
||||
protected string LoggerName(RouteData routeData)
|
||||
{
|
||||
return ControllerContext.RouteData.Values["action"].ToString()
|
||||
.Equals("Action", StringComparison.InvariantCultureIgnoreCase);
|
||||
var controller = RouteData.Values["controller"].ToString();
|
||||
var action = RouteData.Values["action"].ToString();
|
||||
return $"LeafWeb.WebCms.Controllers.{controller}Controller.{action}";
|
||||
}
|
||||
|
||||
// Status messages to pages
|
||||
protected enum StatusType
|
||||
{
|
||||
Info,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace LeafWeb.WebCms.Controllers
|
||||
{
|
||||
// Umbraco page IDs for LeafWeb application pages
|
||||
public static class LeafWebPageIds
|
||||
{
|
||||
public const int ManageQueue = 1107;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace LeafWeb.WebCms.Controllers
|
||||
orderby li.Id descending
|
||||
select li
|
||||
).ToList()
|
||||
.Select(leafInput => new ResultItemViewModel(leafInput));
|
||||
.Select(leafInput => new QueueItemViewModel(leafInput));
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user