Disco.Services.JobActionExtensions.OnCloseForced C# (CSharp) Method

OnCloseForced() public static method

public static OnCloseForced ( this j, DiscoDataContext Database, User Technician, string Reason ) : void
j this
Database Disco.Data.Repository.DiscoDataContext
Technician Disco.Models.Repository.User
Reason string
return void
        public static void OnCloseForced(this Job j, DiscoDataContext Database, User Technician, string Reason)
        {
            if (!j.CanCloseForced())
                throw new InvalidOperationException("Force Close was Denied");

            // Write Log
            JobLog jobLog = new JobLog()
            {
                JobId = j.Id,
                TechUserId = Technician.UserId,
                Timestamp = DateTime.Now,
                Comments = string.Format("# Job Forcibly Closed\r\n{0}", string.IsNullOrWhiteSpace(Reason) ? "<no reason provided>" : Reason)
            };
            Database.JobLogs.Add(jobLog);

            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