Job Expressions

Expressions can be triggered when jobs are created and closed
This commit is contained in:
Gary Sharp
2016-11-09 22:26:43 +11:00
parent 065b14b158
commit b52cbcb94a
22 changed files with 902 additions and 41 deletions
+46 -1
View File
@@ -2,6 +2,7 @@
using Disco.Models.BI.Config;
using Disco.Models.Repository;
using Disco.Services.Authorization;
using Disco.Services.Logging;
using Disco.Services.Plugins;
using Disco.Services.Plugins.Features.RepairProvider;
using Disco.Services.Plugins.Features.WarrantyProvider;
@@ -491,13 +492,35 @@ namespace Disco.Services
#endregion
#region Close
public static void OnCloseNormally(this Job j, User Technician)
public static void OnCloseNormally(this Job j, DiscoDataContext Database, User Technician)
{
if (!j.CanCloseNormally())
throw new InvalidOperationException("Close was Denied");
j.ClosedDate = DateTime.Now;
j.ClosedTechUserId = Technician.UserId;
j.ClosedTechUser = Technician;
// Evaluate OnClose Expression
try
{
var onCloseResult = j.EvaluateOnCloseExpression(Database);
if (!string.IsNullOrWhiteSpace(onCloseResult))
{
var jl = new JobLog()
{
Job = j,
TechUser = Technician,
Timestamp = DateTime.Now,
Comments = onCloseResult
};
Database.JobLogs.Add(jl);
}
}
catch (Exception ex)
{
SystemLog.LogException("Job Expression - OnCloseExpression", ex);
}
}
private static bool CanCloseNever(this Job j, JobQueueJob IgnoreJobQueueJob = null)
@@ -645,6 +668,28 @@ namespace Disco.Services
j.ClosedDate = DateTime.Now;
j.ClosedTechUserId = Technician.UserId;
j.ClosedTechUser = Technician;
// Evaluate OnClose Expression
try
{
var onCloseResult = j.EvaluateOnCloseExpression(Database);
if (!string.IsNullOrWhiteSpace(onCloseResult))
{
var jl = new JobLog()
{
Job = j,
TechUser = Technician,
Timestamp = DateTime.Now,
Comments = onCloseResult
};
Database.JobLogs.Add(jl);
}
}
catch (Exception ex)
{
SystemLog.LogException("Job Expression - OnCloseExpression", ex);
}
}
#endregion