public static string GetNoteForChanges(JobNotificationChanges changes) { //No need for remoting call here. string note = ""; if (changes.HasFlag(JobNotificationChanges.NoteAdded)) { note += "A note was added.\r\n"; } if (changes.HasFlag(JobNotificationChanges.ConceptChange)) { note += "Concept was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.WriteupChange)) { note += "Writeup was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.ApprovalChange)) { note += "Approval Status was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.EngineerChange)) { note += "Engineer was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.ExpertChange)) { note += "Expert was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.CategoryChange)) { note += "Category was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.PhaseChange)) { note += "Phase was changed.\r\n"; } if (changes.HasFlag(JobNotificationChanges.PriorityChange)) { note += "Priority was changed.\r\n"; } return(note.Trim()); }
public static long UpsertNotification(long jobNum, long userNum, JobNotificationChanges changes) { //No need for remoting call here. JobNotification notification = GetForJobAndUser(jobNum, userNum); if (notification == null) { notification = new JobNotification(); notification.JobNum = jobNum; notification.UserNum = userNum; notification.Changes = changes; return(Insert(notification)); } else { notification.Changes = notification.Changes | changes; Update(notification); return(notification.JobNotificationNum); } }
public static void UpsertAllNotifications(Job job, long userNumExcluded, JobNotificationChanges changes) { if (job.PhaseCur.In(JobPhase.Cancelled, JobPhase.Complete, JobPhase.Documentation)) { if (job.ListJobNotifications.Count > 0) { DeleteForJob(job.JobNum); //Delete all notifications that were on jobs once they are no longer in development } return; //Don't send notifications after a job has gotten past development } List <long> listUserNums = job.ListJobLinks.Where(x => x.LinkType == JobLinkType.Subscriber).Select(x => x.FKey) .Union(Jobs.GetAssociatedUsers(job).Select(y => y.UserNum)).Distinct().ToList(); foreach (long userNum in listUserNums) { if (userNum == userNumExcluded) { continue; } UpsertNotification(job.JobNum, userNum, changes); } }
/// <summary>Inserts log entry to DB and returns the resulting JobLog. Returns null if no log was needed.</summary> public static JobLog MakeLogEntry(Job jobNew, Job jobOld, bool isManualLog = false) { if (jobNew == null) { return(null); } JobNotificationChanges changes = new JobNotificationChanges(); JobLog jobLog = new JobLog() { JobNum = jobNew.JobNum, UserNumChanged = Security.CurUser.UserNum, UserNumExpert = jobNew.UserNumExpert, UserNumEngineer = jobNew.UserNumEngineer, Description = "", TimeEstimate = TimeSpan.FromHours(jobNew.HoursEstimate) }; if (isManualLog) { jobLog.Description = "Manual \"last worked on\" update"; JobLogs.Insert(jobLog); return(JobLogs.GetOne(jobLog.JobLogNum)); //to get new timestamp. } List <string> logDescriptions = new List <string>(); if (jobOld.IsApprovalNeeded && !jobNew.IsApprovalNeeded) { if (jobOld.PhaseCur == JobPhase.Concept && (jobNew.PhaseCur == JobPhase.Definition || jobNew.PhaseCur == JobPhase.Development)) { logDescriptions.Add("Concept approved."); jobLog.MainRTF = jobNew.Implementation; jobLog.RequirementsRTF += jobNew.Requirements; changes = changes | JobNotificationChanges.ApprovalChange; } if ((jobOld.PhaseCur == JobPhase.Concept || jobOld.PhaseCur == JobPhase.Definition) && jobNew.PhaseCur == JobPhase.Development) { logDescriptions.Add("Job approved."); jobLog.MainRTF = jobNew.Implementation; jobLog.RequirementsRTF += jobNew.Requirements; changes = changes | JobNotificationChanges.ApprovalChange; } if (jobOld.PhaseCur == JobPhase.Development && jobNew.PhaseCur == JobPhase.Development) { logDescriptions.Add("Changes approved."); jobLog.MainRTF = jobNew.Implementation; jobLog.RequirementsRTF += jobNew.Requirements; changes = changes | JobNotificationChanges.ApprovalChange; } } else if (jobNew.PhaseCur.In(JobPhase.Documentation, JobPhase.Complete) && !jobOld.PhaseCur.In(JobPhase.Documentation, JobPhase.Complete)) { logDescriptions.Add("Job implemented."); jobLog.MainRTF += jobNew.Implementation; jobLog.RequirementsRTF += jobNew.Requirements; } if (jobOld.PhaseCur > jobNew.PhaseCur && jobOld.PhaseCur != JobPhase.Cancelled) { logDescriptions.Add("Job Unapproved."); //may be a chance for a false positive when using override permission. } if (jobOld.PhaseCur != JobPhase.Cancelled && jobNew.PhaseCur == JobPhase.Cancelled) { logDescriptions.Add("Job Cancelled."); //may be a chance for a false positive when using override permission. } if (jobNew.UserNumExpert != jobOld.UserNumExpert) { logDescriptions.Add("Expert changed."); changes = changes | JobNotificationChanges.ExpertChange; } if (jobNew.UserNumEngineer != jobOld.UserNumEngineer) { logDescriptions.Add("Engineer changed."); changes = changes | JobNotificationChanges.EngineerChange; } if (jobOld.Requirements != jobNew.Requirements) { logDescriptions.Add("Job Requirements Changed."); jobLog.RequirementsRTF += jobNew.Requirements; changes = changes | JobNotificationChanges.ConceptChange; } if (jobOld.Implementation != jobNew.Implementation) { logDescriptions.Add("Job Implementation Changed."); jobLog.MainRTF += jobNew.Implementation; changes = changes | JobNotificationChanges.WriteupChange; } //Do not log RequirementsJSON changes here. //if(jobOld.RequirementsJSON!=jobNew.RequirementsJSON) { // logDescriptions.Add("Job Requirements List Changed."); // changes=changes|JobNotificationChanges.ConceptChange; //} if (jobOld.Title != jobNew.Title) { logDescriptions.Add("Job Title Changed."); } if (jobOld.HoursEstimate != jobNew.HoursEstimate) { logDescriptions.Add("Job Estimate Changed from " + jobOld.HoursEstimate.ToString() + " hour(s) to " + jobNew.HoursEstimate.ToString() + " hour(s)."); } jobLog.Title = jobNew.Title; jobLog.Description = string.Join("\r\n", logDescriptions); if (string.IsNullOrEmpty(jobLog.Description)) { return(null); } JobLogs.Insert(jobLog); JobNotifications.UpsertAllNotifications(jobNew, Security.CurUser.UserNum, changes); return(JobLogs.GetOne(jobLog.JobLogNum)); //to get new timestamp. }