Add cancel
This commit is contained in:
@@ -20,6 +20,7 @@ namespace LeafWeb.WebCms.Services
|
||||
private const string EmailSuccessSubject = "LeafWeb results";
|
||||
private const string EmailErrorSubject = "LeafWeb processing error";
|
||||
private const string EmailSystemErrorSubject = "LeafWeb system error";
|
||||
private const string EmailCancelledSubject = "LeafWeb cancelled";
|
||||
|
||||
/// <summary>
|
||||
/// Comma separated values
|
||||
@@ -32,6 +33,11 @@ namespace LeafWeb.WebCms.Services
|
||||
|
||||
private readonly DownloadUrlService _downloadUrlService;
|
||||
|
||||
private string FormatSubject(string subject, LeafInput leafInput)
|
||||
{
|
||||
return subject + $" - '{leafInput.Identifier}'";
|
||||
}
|
||||
|
||||
public EmailNotificationService(DataService dataService)
|
||||
{
|
||||
_dataService = dataService;
|
||||
@@ -60,8 +66,10 @@ namespace LeafWeb.WebCms.Services
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
if (leafInput.CurrentStatus != LeafInputStatusType.Complete)
|
||||
{
|
||||
Logger.Error($"Attempting to SendLeafWebComplete when status is not complete for leafInput: {leafInput}, current status: {leafInput.CurrentStatus}");
|
||||
throw new ArgumentException($"Attempting to SendLeafWebComplete when status is not complete for leafInput: {leafInput}, current status: {leafInput.CurrentStatus}");
|
||||
var notComplete = "Attempting to SendLeafWebComplete when status is not complete" +
|
||||
$" for leafInput: {leafInput}, current status: {leafInput.CurrentStatus}";
|
||||
Logger.Error(notComplete);
|
||||
throw new ArgumentException(notComplete);
|
||||
}
|
||||
|
||||
var outputErrorMessage = leafInput.OutputErrorMessage;
|
||||
@@ -71,6 +79,24 @@ namespace LeafWeb.WebCms.Services
|
||||
SendLeafWebSuccess(leafInput);
|
||||
}
|
||||
|
||||
public void SendLeafWebCancelled(int leafInputId)
|
||||
{
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
if (leafInput.CurrentStatus != LeafInputStatusType.Cancelled)
|
||||
{
|
||||
var notComplete = "Attempting to SendLeafWebCancelled when status is not complete " +
|
||||
$"for leafInput: {leafInput}, current status: {leafInput.CurrentStatus}";
|
||||
Logger.Error(notComplete);
|
||||
throw new ArgumentException(notComplete);
|
||||
}
|
||||
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, has been cancelled. " +
|
||||
"Contact the administrator with any questions.";
|
||||
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, FormatSubject(EmailCancelledSubject, leafInput), body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
public void SendAdministratorMessage(string subject, string body)
|
||||
{
|
||||
var message = new MailMessage(_emailFromAddress, _adminEmailAddresses, subject, body);
|
||||
@@ -94,7 +120,7 @@ namespace LeafWeb.WebCms.Services
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ downloadUrl;
|
||||
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, EmailSuccessSubject, body);
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, FormatSubject(EmailSuccessSubject, leafInput), body);
|
||||
SendMessage(message);
|
||||
}
|
||||
else
|
||||
@@ -138,7 +164,7 @@ namespace LeafWeb.WebCms.Services
|
||||
|
||||
body += FormatWarningMessage(leafInput);
|
||||
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, EmailErrorSubject, body);
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, FormatSubject(EmailErrorSubject, leafInput), body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user