private List<IssueResponse> ProcessIssueRevisionHistory(Issue oldIssue, Issue newIssue, CmsEntities cee, IssueModifications issueModifications) { log.Verbose("ProcessIssueRevisionHistory()"); var responses = new List<IssueResponse>(); try { if (oldIssue == null) return responses; //We are adding new ISSUE List<User> users = (from x in cee.Users select x).ToList(); //RESPONSE responses.AddRange(ProcessIssueResponseRevisionHistory(newIssue)); //STATUS responses.AddRange(ProcessIssueStatusRevisionHistory(newIssue, oldIssue)); //APPROVAL responses.AddRange(ProcessIssueApprovalsRevisionHistory(newIssue, oldIssue, issueModifications)); //INITIAL / FINAL RISKS responses.AddRange(ProcessIssueRisksRevisionHistory(newIssue, oldIssue, cee)); //PRIORITY responses.AddRange(ProcessIssuePriorityRevisionHistory(newIssue, oldIssue)); //TYPE responses.AddRange(ProcessIssueTypeRevisionHistory(newIssue, oldIssue)); //SUB TYPE responses.AddRange(ProcessIssueSubTypeRevisionHistory(newIssue, oldIssue)); //ASSIGNED TO responses.AddRange(ProcessIssueAssignedToRevisionHistory(newIssue, oldIssue, users)); //CLASSIFICATION responses.AddRange(ProcessIssueClassificationRevisionHistory(newIssue, oldIssue)); //CATEGORIES responses.AddRange(ProcessIssueCategoriesRevisionHistory(newIssue, oldIssue)); //TITLE responses.AddRange(ProcessIssueTitleRevisionHistory(newIssue, oldIssue)); //DESCRIPTION responses.AddRange(ProcessIssueDescriptionRevisionHistory(newIssue, oldIssue)); //REASON responses.AddRange(ProcessIssueReasonRevisionHistory(newIssue, oldIssue)); //SUGGESTED SOLUTION responses.AddRange(ProcessIssueSuggestedSolutionRevisionHistory(newIssue, oldIssue)); //DISTRIBUTION LIST responses.AddRange(ProcessIssueDistributionListRevisionHistory(newIssue, oldIssue, users)); //ISSUE START DATE responses.AddRange(ProcessIssueStartDateRevisionHistory(newIssue, oldIssue)); //ISSUE END DATE responses.AddRange(ProcessIssueEndDateRevisionHistory(newIssue, oldIssue)); //ACTIONS responses.AddRange(ProcessIssueActionsRevisionHistory(newIssue, oldIssue, users,cee)); //ProjectSupervisor responses.AddRange(ProcessProjectSupervisorRevisionHistory(newIssue, oldIssue, users)); //Issue Closeouts responses.AddRange(ProcessIssueCloseouts(newIssue, oldIssue)); //Issue System References responses.AddRange(ProcessIssueSystemReferencesRevisionHistory(newIssue, oldIssue)); //Issue Tracking responses.AddRange(ProcessIssueTrackingRevisionHistory(newIssue, oldIssue)); //Issue trend Notices responses.AddRange(ProcessIssueTrendsRevisionHistory(newIssue, oldIssue, cee)); //Issue Milestones responses.AddRange(ProcessIssueMilestonesRevisionHistory(newIssue, oldIssue)); //Issue Attachments - Removed by request https://jira.issgroup.com.au/browse/BODCMS-1800?focusedCommentId=80320&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-80320 // So it's not needed as Add/Remove revision history is done when attachment is added/deleted //responses.AddRange(ProcessIssueAttachmentsRevisionHistory(newIssue, oldIssue, cee)); //Issue Learnings responses.AddRange(ProcessIssueLearningsRevisionHistory(newIssue, oldIssue)); //Issue Key Stakeholders responses.AddRange(ProcessIssueKeyStakeholdersRevisionHistory(newIssue, oldIssue)); } catch (Exception ex) { log.Error("", ex, "Error occured in ProcessIssueRevisionHistory()"); throw new Exception("Error while processing Revision History", ex); } return responses; }
private EmailNotification GetEmailNotificationObject(IssueModifications issueModifications, User user, CmsEntities cee) { log.Verbose("GetEmailNotificationObject()"); //Process only if its enable in web.config string emailEnabledSettingValue = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailSendEnabled); string disableEmailUpdatesFromAdminUserSettingValue = "false"; int sysAdminRoleId = (from x in cee.Roles where x.Name.Equals("SYS-ADMIN", StringComparison.CurrentCultureIgnoreCase) select x.Id).FirstOrDefault(); if (user.RoleId == sysAdminRoleId) { disableEmailUpdatesFromAdminUserSettingValue = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.DisableEmailUpdatesFromAdminUser); } if (emailEnabledSettingValue.ToLower() == "true" && disableEmailUpdatesFromAdminUserSettingValue.ToLower() == "false") { IEnumerable<IEmailNotificatonPlugin> plugins = Util.GetIssueEmailNotificatonPlugins(); // ReSharper disable once PossibleMultipleEnumeration if (plugins.Any()) { //take first we find. // ReSharper disable once PossibleMultipleEnumeration IEmailNotificatonPlugin plugin = (from x in plugins select x).FirstOrDefault(); if (plugin != null) { return plugin.GetEmailNotificationObject(issueModifications); } else { log.Warning("", "GetEmailNotificationObject - no plugins found!"); } } else { log.Warning("", "GetEmailNotificationObject - no plugins found!"); } } else { if (emailEnabledSettingValue.ToLower() != "true") log.Info("Send Email Setting is set to False. Will not send email."); else if (disableEmailUpdatesFromAdminUserSettingValue.ToLower() != "false") log.Info("Disable Updates From Admin User Setting is set to True. Will not send email."); } return null; }
private IEnumerable<IssueResponse> ProcessIssueApprovalsRevisionHistory(Issue newIssue, Issue oldIssue, IssueModifications issueModifications) { var responses = new List<IssueResponse>(); try { foreach (IssueApproval oldApproval in oldIssue.IssueApprovals) { IssueApproval newApproval = (from x in newIssue.IssueApprovals where x.IssueId == oldApproval.IssueId && x.IssueCategoryId == oldApproval.IssueCategoryId select x).FirstOrDefault(); if (newApproval != null) { if (!oldApproval.Approved && newApproval.Approved) { //OldApproval was not approved, NewApproval is Approved string response = String.Format("Category '{0}' approved by '{1}'", newApproval.IssueCategory.Name, newApproval.Approver.FirstLastName); responses.Add(CreateIssueResponse(newIssue, response, true)); //issueModifications.HasApprovalChanges = true; issueModifications.CategoryApprovedNames.Add(newApproval.IssueCategory.Name); } else if (oldApproval.Approved && !newApproval.Approved) { //OldApproval was approved, NewApproval is not Approved string response = String.Format("Category '{0}' unapproved by '{1}'", newApproval.IssueCategory.Name, newApproval.Approver.FirstLastName); responses.Add(CreateIssueResponse(newIssue, response, true)); //issueModifications.HasUnApprovalChanges = true; issueModifications.CategoryUnApprovedNames.Add(newApproval.IssueCategory.Name); } } //else //{ // //Old Approval was removed // var response = String.Format("Approval category '{0}' was removed", oldApproval.IssueCategory.Name); // responses.Add(CreateIssueResponse(newIssue, response)); //} } } catch (Exception ex) { throw new Exception("Error in ProcessIssueApprovalsRevisionHistory()", ex); } return responses; }
public DbOperationResult<QuickIssue> SaveIssue(Issue issue) { //issueModifications is a helper class for sending email. var issueModifications = new IssueModifications { Issue = issue }; try { Stopwatch sw = new Stopwatch(); sw.Start(); EmailNotification emailNotificationObject; using (var transaction = new TransactionScope()) { using (var cee = new CmsEntities()) { cee.Configuration.AutoDetectChangesEnabled = false; cee.Configuration.ValidateOnSaveEnabled = false; User modifiedByUser = (from x in cee.Users where x.Id == issue.ModifiedById select x).FirstOrDefault(); if (modifiedByUser == null) { throw new NullReferenceException(string.Format("Save Issue Failed: Cannot find a user in db using Id {0}", issue.ModifiedById)); } log.Info("Saving Issue Id {0}. User = '******'", issue.Id, modifiedByUser.FirstLastName); cee.Configuration.LazyLoadingEnabled = true; Issue originalIssue = (from x in cee.Issues .Include("IssueStatus") .Include("IssuePriority") .Include("IssueType") .Include("IssueClassification") .Include("CurrentlyAssignedToUser") where x.Id == issue.Id select x).FirstOrDefault(); issueModifications.OriginalIssue = originalIssue; issue.ModifiedDate = DateTime.Now; List<IssueResponse> responses = ProcessIssueRevisionHistory(originalIssue, issue, cee, issueModifications); responses.Reverse(); if (originalIssue != null) { //We are updating the ISSUE emailNotificationObject = GetEmailNotificationObject(issueModifications, modifiedByUser, cee); //Save only changed objects SaveIssueRelatedObjects(issue, originalIssue, cee, modifiedByUser.Id); //Update current issue cee.Entry(originalIssue).CurrentValues.SetValues(issue); responses.ForEach(x => originalIssue.IssueResponses.Add(x)); } else { emailNotificationObject = GetEmailNotificationObject(issueModifications, modifiedByUser, cee); int classificaitonId = issue.IssueClassificationId.HasValue ? issue.IssueClassificationId.Value : 0; int? subtTypeId = issue.IssueSubTypeId; int currentlyAssignedToUserId = issue.CurrentlyAssignedToId; //We are creating new ISSUE issue.IsActive = true; //default; issue.CurrentlyAssignedToUser = null; issue.InitiatedByUser = null; issue.IssueClassification = null; issue.IssueClassificationId = classificaitonId; issue.IssueSubType = null; issue.IssueSubTypeId = subtTypeId; issue.IssuePriority = null; issue.IssueStatus = null; issue.IssueType = null; issue.IssuePriority = null; issue.ModifiedByUser = null; issue.OriginallyAssignedToUser = null; issue.CurrentlyAssignedToId = currentlyAssignedToUserId; //SaveIssueCloseouts(issue, issue, cee); AddStandardActions(issue, cee); cee.Issues.Add(issue); responses.ForEach(x => issue.IssueResponses.Add(x)); } cee.SaveChanges(); transaction.Complete(); if (emailNotificationObject != null) { emailNotificationObject.HasResponse = responses.Any(); } } } if (emailNotificationObject != null) { emailNotificationObject.IssueId = issue.Id; StartEmailPlugin(emailNotificationObject); } sw.Stop(); log.Verbose("Took {0} seconds to save IssueId '{1}'", sw.Elapsed.TotalSeconds, issue.Id); return new DbOperationResult<QuickIssue> { EntityResult = BuildReturnQuickIssue(issue) }; } catch (Exception ex) { string errorMsg = string.Format("Error occured while saving Issue Id {0}", issue.Id); log.Error("", ex, errorMsg); return BuildOperationalErrorResults<QuickIssue>(ex); } }