public void ImportIssues() { mForm.AddMessage(MessageType.Info, "-------------------- Importing Issues --------------------"); //List<Issue> oldIssues = (from x in mOldIssuesDataContext.Issues where x.Id == 838 select x).ToList(); List<Issue> oldIssues = (from x in mOldIssuesDataContext.Issues select x).ToList(); var oldUsers = (from x in mOldIssuesDataContext.Users select x).ToList(); var oldRiskMatrixes = (from x in mOldIssuesDataContext.RiskMatrixes select x).ToList(); var oldPriorities = (from x in mOldIssuesDataContext.Priorities select x).ToList(); var oldStatuses = (from x in mOldIssuesDataContext.Status select x).ToList(); var newIssues = (from x in mCee.Issues select x).ToList(); var newUsers = (from x in mCee.Users.Include("Role") select x).ToList(); var newIssueTypes = (from x in mCee.IssueTypes select x).ToList(); var newIssuePriorities = (from x in mCee.IssuePriorities select x).ToList(); var newIssueStatuses = (from x in mCee.IssueStatuses select x).ToList(); var newIssueCategories = (from x in mCee.IssueCategories select x).ToList(); var newIssueAssignedCategories = (from x in mCee.IssueAssignedCategories select x).ToList(); var newIssueDistributionUsers = (from x in mCee.IssueDistributionUsers select x).ToList(); var newIssueApprovals = (from x in mCee.IssueApprovals select x).ToList(); var newControlModules = (from x in mCee.ControlModules select x).ToList(); var newIssueRelatedSoftwares = (from x in mCee.IssueRelatedSoftwares select x).ToList(); var newIssueRelatedGraphics = (from x in mCee.IssueRelatedGraphics select x).ToList(); var newIssueRelatedPcsEquipments = (from x in mCee.IssueRelatedPcsEquipments select x).ToList(); var newIssueRelatedOverrides = (from x in mCee.IssueRelatedOverrides select x).ToList(); var newIssueRelatedMechanicalEquipments = (from x in mCee.IssueRelatedMechanicalEquipments select x).ToList(); var newIssueRelatedElectricalEquipments = (from x in mCee.IssueRelatedElectricalEquipments select x).ToList(); var newIssueRelatedDocuments = (from x in mCee.IssueRelatedDocuments select x).ToList(); var newIssueFiles = (from x in mCee.IssueFiles select x).ToList(); var newIssueRiskConsequences = (from x in mCee.IssueRiskConsequences select x).ToList(); var newIssueRiskMatrices = (from x in mCee.IssueRiskMatrices select x).ToList(); var newIssueRisks = (from x in mCee.IssueRisks select x).ToList(); var newIssueClassifications = (from x in mCee.IssueClassifications select x).ToList(); var newDocuments = (from x in mCee.Documents select x).ToList(); var newAreas = (from x in mCee.Areas select x).ToList(); var newIssueAreas = (from x in mCee.IssueAreas select x).ToList(); var notSpecifiedAttachmentType = (from x in mCee.AttachmentTypes where x.Name.ToLower() == "not specified" select x.Id).FirstOrDefault(); var initialRiskTypeId = (from x in mCee.IssueRiskTypes where x.Name.ToLower() == "initial risk" select x.Id).FirstOrDefault(); var finalRiskTypeId = (from x in mCee.IssueRiskTypes where x.Name.ToLower() == "final risk" select x.Id).FirstOrDefault(); var financeCategoryId = (from x in mCee.IssueRiskCategories where x.Name.ToLower() == "finance" select x.Id).FirstOrDefault(); var hslpCategoryId = (from x in mCee.IssueRiskCategories where x.Name.ToLower() == "hslp" select x.Id).FirstOrDefault(); var environmentCategoryId = (from x in mCee.IssueRiskCategories where x.Name.ToLower() == "environment" select x.Id).FirstOrDefault(); var communityCategoryId = (from x in mCee.IssueRiskCategories where x.Name.ToLower() == "community" select x.Id).FirstOrDefault(); var operationalCategoryId = (from x in mCee.IssueRiskCategories where x.Name.ToLower() == "operational" select x.Id).FirstOrDefault(); using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = TimeSpan.FromMinutes(30) })) { foreach (var oldIssue in oldIssues) { try { var issueExist = (from x in newIssues where x.Id == oldIssue.Id select x).FirstOrDefault(); if (issueExist != null) { mForm.AddMessage(MessageType.Warning, String.Format("Issue #{0} already exist, skipping.", oldIssue.Id)); continue; } mForm.AddMessage(MessageType.Info, "Importing Issue #" + oldIssue.Id); var oldOriginallyAssignedToUser = (from x in oldUsers where x.Id == oldIssue.OriginallyAssignedToId select x).FirstOrDefault(); var originallyAssignedToUser = (from x in newUsers where x.UserName == oldOriginallyAssignedToUser.UserName select x).FirstOrDefault(); var oldCurrentlyAssignedToUser = (from x in oldUsers where x.Id == oldIssue.CurrentlyAssignedToId select x).FirstOrDefault(); var currentlyAssignedToUser = (from x in newUsers where x.UserName == oldCurrentlyAssignedToUser.UserName select x).FirstOrDefault(); var oldModifiedByUser = (from x in oldUsers where x.Id == oldIssue.ModifiedById select x).FirstOrDefault(); var newModifiedByUser = (from x in newUsers where x.UserName == oldModifiedByUser.UserName select x).FirstOrDefault(); var issueType = (from x in newIssueTypes where x.Name == oldIssue.IssueType.Name select x).FirstOrDefault(); var issuePriority = (from x in newIssuePriorities where x.Name == oldIssue.Priority.Name select x).FirstOrDefault(); var issueStatus = (from x in newIssueStatuses where x.Name == oldIssue.Status.Name select x).FirstOrDefault(); var oldInitiatedByUser = (from x in oldUsers where x.Id == oldIssue.InitiatedById select x).FirstOrDefault(); var newInitiatedByUser = (from x in newUsers where x.UserName == oldInitiatedByUser.UserName select x).FirstOrDefault(); CmsEquipmentDatabase.CmsWebService.Issue newIssue = new CmsEquipmentDatabase.CmsWebService.Issue() { Id = oldIssue.Id, Name = oldIssue.Name, Description = oldIssue.Description, OriginallyAssignedToId = originallyAssignedToUser.Id, CurrentlyAssignedToId = currentlyAssignedToUser.Id, ModifiedById = newModifiedByUser.Id, ModifiedDate = oldIssue.ModifiedDate, IssueTypeId = issueType.Id, IssuePriorityId = issuePriority.Id, IssueStatusId = issueStatus.Id, InitiatedById = newInitiatedByUser.Id, InitiatedDate = oldIssue.InitiatedDate, Reason = oldIssue.Reason, Hazard = oldIssue.Hazard, ControlMethod = oldIssue.ControlMethod, SuggestedSolution = oldIssue.SuggestedSolution, ImplementationDetails = oldIssue.ImplementationDetails, TestingDetails = oldIssue.TestingDetails, RequestedBy = oldIssue.RequestedBy, TimeToImplement = oldIssue.TimeToImplement, TimeToTest = oldIssue.TimeToTest, TimeToDocument = oldIssue.TimeToDocument, ApproveNote = oldIssue.ApproveNote, ActualTimeImplement = oldIssue.ActualTimeImplement, ActualTimeTest = oldIssue.ActualTimeTest, ActualTimeDocument = oldIssue.ActualTimeDocument, RefNumber = oldIssue.KdcrNumber, TrainingDetails = oldIssue.TrainingDetails, IsActive = true }; if (oldIssue.ClassificationId.HasValue) { var classification = (from x in newIssueClassifications where x.Name == oldIssue.Classification.Name select x).FirstOrDefault(); newIssue.IssueClassificationId = classification.Id; } var oldDesignedByUser = (from x in oldUsers where x.Id == oldIssue.DesignedById select x).FirstOrDefault(); if (oldDesignedByUser != null) { var newDesignedByUser = (from x in newUsers where x.UserName == oldDesignedByUser.UserName select x).FirstOrDefault(); newIssue.DesignedById = newDesignedByUser.Id; } mCee.Issues.AddObject(newIssue); #region Issue Areas mForm.AddMessage(MessageType.Info, "-------------------- Updating UpdateIssueAreas --------------------"); if (oldIssue.Areas != null) { var issueAreas = oldIssue.Areas.Split(','); foreach (var issueArea in issueAreas) { var area = newAreas.Where(x => x.Name.ToLower() == issueArea.Trim().ToLower()).FirstOrDefault(); if (area != null) { var existingIssueArea = (from x in newIssueAreas where x.IssueId == newIssue.Id && x.AreaId == area.Id select x).FirstOrDefault(); if (existingIssueArea == null) { var addIssueArea = new IssueArea {IssueId = newIssue.Id, AreaId = area.Id}; mCee.IssueAreas.AddObject(addIssueArea); newIssueAreas.Add(addIssueArea); } else { string message = String.Format("Area '{0}' from Issue ID '{1}' is already assigned to the Issue.", issueArea, newIssue.Id); mForm.AddMessage(MessageType.Error, message); } } else { string message = String.Format("Area '{0}' from Issue ID '{1}' doesn't exist, skipping", issueArea, newIssue.Id); mForm.AddMessage(MessageType.Warning, message); } } } else { string message = String.Format("Issue Id '{0}' does not have any Area(s) assigned", newIssue.Id); mForm.AddMessage(MessageType.Warning, message); } #endregion mForm.AddMessage(MessageType.Info, "-------------------- Updating Issue Categories --------------------"); #region Issue Category var issueCategory = (from x in newIssueCategories where x.Name == oldIssue.Category.Name select x).FirstOrDefault(); if (issueCategory == null) { string message = String.Format("Issue Category '{0}' does not exist in the database, skipping Issue id '{1}", oldIssue.Category.Name, oldIssue.Id); mForm.AddMessage(MessageType.Error, message); throw new Exception(message); } IssueAssignedCategory issueAssignedCategory = new IssueAssignedCategory(); issueAssignedCategory.IssueCategoryId = issueCategory.Id; issueAssignedCategory.IssueId = oldIssue.Id; mCee.IssueAssignedCategories.AddObject(issueAssignedCategory); newIssueAssignedCategories.Add(issueAssignedCategory); #endregion #region Distribution Users IssueDistributionUser distributionUser; //Add Users to Distribution List if (!String.IsNullOrEmpty(oldIssue.EmailUserList)) { int emailUserId = -1; string[] emailUsers = oldIssue.EmailUserList.Split(','); foreach (var emailUser in emailUsers) { if (int.TryParse(emailUser, out emailUserId)) { var oldUser = (from x in oldUsers where x.Id == emailUserId select x).FirstOrDefault(); if (oldUser != null) { var user = (from x in newUsers where x.UserName == oldUser.UserName select x).FirstOrDefault(); distributionUser = new IssueDistributionUser(); distributionUser.IssueId = oldIssue.Id; distributionUser.UserId = user.Id; var issueAssignedCategories = (from x in newIssueAssignedCategories where x.IssueId == oldIssue.Id select x).ToList(); //Dont allow to delete user if he/she is a defaultCategoryUser var defaultCategoryUser = issueAssignedCategories.Where( x => x.IssueCategory.IssueCategoryUsers.Contains( (from xx in mCee.IssueCategoryUsers where xx.IssueCategoryId == x.IssueCategoryId && xx.UserId == user.Id select xx).FirstOrDefault())).FirstOrDefault(); if (defaultCategoryUser != null && defaultCategoryUser.Id == user.Id) { distributionUser.AllowDeletion = false; } else { distributionUser.AllowDeletion = true; } distributionUser.AllowDeletion = true; var userExist = (from x in newIssueDistributionUsers where x.IssueId == oldIssue.Id && x.UserId == user.Id select x).FirstOrDefault(); if (userExist == null) { mCee.IssueDistributionUsers.AddObject(distributionUser); newIssueDistributionUsers.Add(distributionUser); } } else { string message = String.Format("User ID '{0}' from EmailuserList for Issue '{1}' does not exist in the database.", emailUserId, oldIssue.Id); mForm.AddMessage(MessageType.Error, message); } } } } #endregion #region Issue Category User foreach (var issueCategoryUser in issueCategory.IssueCategoryUsers) { //Add default user from category distributionUser = new IssueDistributionUser(); distributionUser.IssueId = oldIssue.Id; distributionUser.UserId = issueCategoryUser.UserId; var userExist = (from x in newIssueDistributionUsers where x.IssueId == oldIssue.Id && x.UserId == distributionUser.UserId select x).FirstOrDefault(); if (userExist == null) { mCee.IssueDistributionUsers.AddObject(distributionUser); newIssueDistributionUsers.Add(distributionUser); } else { userExist.AllowDeletion = false; } IssueApproval issueApproval = new IssueApproval(); issueApproval.IssueId = oldIssue.Id; issueApproval.Approved = false; issueApproval.IssueCategoryId = issueCategory.Id; mCee.IssueApprovals.AddObject(issueApproval); newIssueApprovals.Add(issueApproval); } #endregion #region Approvals //Approvals USER if (oldIssue.Approved) { if (oldIssue.ApprovedById.HasValue && oldIssue.ApprovedDate.HasValue) { var oldUser = (from x in oldUsers where x.Id == oldIssue.ApprovedById.Value select x).FirstOrDefault(); var user = (from x in newUsers where x.UserName == oldUser.UserName select x).FirstOrDefault(); var userDefaultCategoryId = user.Role.DefaultIssueCategoryId; var existinIssueApproval = (from x in newIssueApprovals where x.IssueId == oldIssue.Id && x.IssueCategoryId == userDefaultCategoryId select x).FirstOrDefault(); if (existinIssueApproval == null) { IssueApproval issueApproval = new IssueApproval(); issueApproval.IssueId = oldIssue.Id; issueApproval.Approved = true; issueApproval.ApproverId = user.Id; issueApproval.Date = oldIssue.ApprovedDate; issueApproval.IssueCategoryId = userDefaultCategoryId; mCee.IssueApprovals.AddObject(issueApproval); newIssueApprovals.Add(issueApproval); } else { existinIssueApproval.Approved = true; existinIssueApproval.ApproverId = user.Id; existinIssueApproval.Date = oldIssue.ApprovedDate; } } else { String message = String.Format("Issue '{0}' was marked as Approved, but user or date was not set!", oldIssue.Id); mForm.AddMessage(MessageType.Error, message); } } //Approvals USER1 if (oldIssue.Approved1.HasValue && oldIssue.Approved1.Value) { if (oldIssue.ApprovedById1.HasValue && oldIssue.ApprovedDate1.HasValue) { var oldUser = (from x in oldUsers where x.Id == oldIssue.ApprovedById1.Value select x).FirstOrDefault(); var user = (from x in newUsers where x.UserName == oldUser.UserName select x).FirstOrDefault(); var userDefaultCategoryId = user.Role.DefaultIssueCategoryId; var existinIssueApproval = (from x in mCee.IssueApprovals where x.IssueId == oldIssue.Id && x.IssueCategoryId == userDefaultCategoryId select x).FirstOrDefault(); if (existinIssueApproval == null) { IssueApproval issueApproval = new IssueApproval(); issueApproval.IssueId = oldIssue.Id; issueApproval.Approved = true; issueApproval.ApproverId = user.Id; issueApproval.Date = oldIssue.ApprovedDate1.Value; issueApproval.IssueCategoryId = userDefaultCategoryId; mCee.IssueApprovals.AddObject(issueApproval); } else { existinIssueApproval.Approved = true; existinIssueApproval.ApproverId = user.Id; existinIssueApproval.Date = oldIssue.ApprovedDate1.Value; } } else { String message = String.Format("Issue '{0}' was marked as Approved1, but user or date was not set!", oldIssue.Id); mForm.AddMessage(MessageType.Error, message); } } //Approvals USER2 if (oldIssue.Approved2.HasValue && oldIssue.Approved2.Value) { if (oldIssue.ApprovedById2.HasValue && oldIssue.ApprovedDate2.HasValue) { var oldUser = (from x in oldUsers where x.Id == oldIssue.ApprovedById2.Value select x).FirstOrDefault(); var user = (from x in newUsers where x.UserName == oldUser.UserName select x).FirstOrDefault(); var userDefaultCategoryId = user.Role.DefaultIssueCategoryId; var existinIssueApproval = (from x in mCee.IssueApprovals where x.IssueId == oldIssue.Id && x.IssueCategoryId == userDefaultCategoryId select x).FirstOrDefault(); if (existinIssueApproval == null) { IssueApproval issueApproval = new IssueApproval(); issueApproval.IssueId = oldIssue.Id; issueApproval.Approved = true; issueApproval.ApproverId = user.Id; issueApproval.Date = oldIssue.ApprovedDate2.Value; issueApproval.IssueCategoryId = userDefaultCategoryId; mCee.IssueApprovals.AddObject(issueApproval); mCee.IssueApprovals.AddObject(issueApproval); } else { existinIssueApproval.Approved = true; existinIssueApproval.ApproverId = user.Id; existinIssueApproval.Date = oldIssue.ApprovedDate2.Value; } } else { String message = String.Format("Issue '{0}' was marked as Approved2, but user or date was not set!", oldIssue.Id); mForm.AddMessage(MessageType.Error, message); } } #endregion #region Related Software mCee.ContextOptions.LazyLoadingEnabled = true; foreach (var oldRelatedSoftware in oldIssue.RelatedSoftwares) { IssueRelatedSoftware irs = new IssueRelatedSoftware(); irs.IssueId = oldIssue.Id; irs.ControlModuleId = oldRelatedSoftware.ControlModuleId; var existingControlModule = (from x in newControlModules where x.Id == oldRelatedSoftware.ControlModuleId select x).FirstOrDefault(); if (existingControlModule == null) { String message = String.Format("Issue '{0}': ControlModuleId '{1}' that is referenced in Related Software '{2}' does not exist. Skipping this Related Software!", oldIssue.Id, oldRelatedSoftware.ControlModuleId, oldRelatedSoftware.Id); mForm.AddMessage(MessageType.Error, message); continue; } try { // //Add areas from Software Area controlModuleArea = null; if (existingControlModule.Unit != null) { controlModuleArea = existingControlModule.Unit.Cell.Area; } else { controlModuleArea = existingControlModule.EquipmentModule.Unit.Cell.Area; } var existingIssueArea = (from x in newIssueAreas where x.IssueId == newIssue.Id && x.AreaId == controlModuleArea.Id select x).FirstOrDefault(); if (existingIssueArea == null) { var addIssueArea = new IssueArea {IssueId = newIssue.Id, AreaId = controlModuleArea.Id}; mCee.IssueAreas.AddObject(addIssueArea); newIssueAreas.Add(addIssueArea); String message = String.Format("Issue '{0}': Added Area Id '{1}' from ControlModuleId '{2}' ", oldIssue.Id, controlModuleArea.Id, oldRelatedSoftware.ControlModuleId); mForm.AddMessage(MessageType.Info, message); } } catch (Exception ex) { string message = String.Format("Error updateding Area from ControlModuleId {0}: {1} Stack Trace {2}, Inner Exeption {3}", existingControlModule.Id, ex.Message, ex.StackTrace, ex.InnerException == null ? String.Empty : ex.InnerException.Message); mForm.AddMessage(MessageType.Error, message); } irs.Implemented = oldRelatedSoftware.Implemented; if (irs.Implemented) { if (oldRelatedSoftware.ImplementedById.HasValue && oldRelatedSoftware.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedSoftware.ImplementedById select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedSoftware.ImplementedDate; } else { String message = String.Format("Issue '{0}': Related Software '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedSoftware.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Loaded = oldRelatedSoftware.Loaded; if (irs.Loaded) { if (oldRelatedSoftware.LoadedById.HasValue && oldRelatedSoftware.LoadedDate.HasValue) { var oldLoadedUser = (from x in oldUsers where x.Id == oldRelatedSoftware.LoadedById select x).FirstOrDefault(); irs.LoadedById = (from x in newUsers where x.UserName == oldLoadedUser.UserName select x).FirstOrDefault().Id; irs.LoadedDate = oldRelatedSoftware.LoadedDate; } else { String message = String.Format("Issue '{0}': Related Software '{1}' was marked as loaded, but user or date was not set!", oldIssue.Id, oldRelatedSoftware.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Tested = oldRelatedSoftware.Tested; if (irs.Tested) { if (oldRelatedSoftware.TestedById.HasValue && oldRelatedSoftware.TestedDate.HasValue) { var oldTestedUser = (from x in oldUsers where x.Id == oldRelatedSoftware.TestedById select x).FirstOrDefault(); irs.TestedById = (from x in newUsers where x.UserName == oldTestedUser.UserName select x).FirstOrDefault().Id; irs.TestedDate = oldRelatedSoftware.TestedDate; } else { String message = String.Format("Issue '{0}': Related Software '{1}' was marked as tested, but user or date was not set!", oldIssue.Id, oldRelatedSoftware.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedSoftware.Notes; mCee.IssueRelatedSoftwares.AddObject(irs); newIssueRelatedSoftwares.Add(irs); } #endregion #region Related Graphic foreach (var oldRelatedGraphic in oldIssue.RelatedGraphics) { IssueRelatedGraphic irs = new IssueRelatedGraphic(); irs.IssueId = oldIssue.Id; irs.GraphicId = oldRelatedGraphic.GraphicId; irs.Implemented = oldRelatedGraphic.Implemented; if (irs.Implemented) { if (oldRelatedGraphic.ImplementedById.HasValue && oldRelatedGraphic.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedGraphic.ImplementedById select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedGraphic.ImplementedDate; } else { String message = String.Format("Issue '{0}': Related Graphic '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedGraphic.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Loaded = oldRelatedGraphic.Loaded; if (irs.Loaded) { if (oldRelatedGraphic.LoadedById.HasValue && oldRelatedGraphic.LoadedDate.HasValue) { var oldLoadedUser = (from x in oldUsers where x.Id == oldRelatedGraphic.LoadedById select x).FirstOrDefault(); irs.LoadedById = (from x in newUsers where x.UserName == oldLoadedUser.UserName select x).FirstOrDefault().Id; irs.LoadedDate = oldRelatedGraphic.LoadedDate; } else { String message = String.Format("Issue '{0}': Related Graphic '{1}' was marked as loaded, but user or date was not set!", oldIssue.Id, oldRelatedGraphic.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Tested = oldRelatedGraphic.Tested; if (irs.Tested) { if (oldRelatedGraphic.TestedById.HasValue && oldRelatedGraphic.TestedDate.HasValue) { var oldTestedUser = (from x in oldUsers where x.Id == oldRelatedGraphic.TestedById select x).FirstOrDefault(); irs.TestedById = (from x in newUsers where x.UserName == oldTestedUser.UserName select x).FirstOrDefault().Id; irs.TestedDate = oldRelatedGraphic.TestedDate; } else { String message = String.Format("Issue '{0}': Related Graphic '{1}' was marked as tested, but user or date was not set!", oldIssue.Id, oldRelatedGraphic.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedGraphic.Notes; mCee.IssueRelatedGraphics.AddObject(irs); newIssueRelatedGraphics.Add(irs); } #endregion #region Related PcsEquipment foreach (var oldRelatedPcsEquipment in oldIssue.RelatedPcsEquipments) { IssueRelatedPcsEquipment irs = new IssueRelatedPcsEquipment(); irs.IssueId = oldIssue.Id; irs.PcsEquipmentId = oldRelatedPcsEquipment.PcsEquipment.Id; irs.Implemented = oldRelatedPcsEquipment.Implemented; if (irs.Implemented) { if (oldRelatedPcsEquipment.ImplementedBy.HasValue && oldRelatedPcsEquipment.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedPcsEquipment.ImplementedBy select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedPcsEquipment.ImplementedDate; } else { String message = String.Format("Issue '{0}': PcsEquipment '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedPcsEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Tested = oldRelatedPcsEquipment.Tested; if (irs.Tested) { if (oldRelatedPcsEquipment.TestedBy.HasValue && oldRelatedPcsEquipment.TestedDate.HasValue) { var oldTestedUser = (from x in oldUsers where x.Id == oldRelatedPcsEquipment.TestedBy select x).FirstOrDefault(); irs.TestedById = (from x in newUsers where x.UserName == oldTestedUser.UserName select x).FirstOrDefault().Id; irs.TestedDate = oldRelatedPcsEquipment.TestedDate; } else { String message = String.Format("Issue '{0}': PcsEquipment '{1}' was marked as tested, but user or date was not set!", oldIssue.Id, oldRelatedPcsEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedPcsEquipment.Notes; mCee.IssueRelatedPcsEquipments.AddObject(irs); newIssueRelatedPcsEquipments.Add(irs); } #endregion #region Related Override foreach (var oldRelatedOverride in oldIssue.RelatedOverrides) { IssueRelatedOverride irs = new IssueRelatedOverride(); irs.IssueId = oldIssue.Id; irs.InterlockId = oldRelatedOverride.InterlockId; irs.Applied = oldRelatedOverride.Applied; if (irs.Applied) { if (oldRelatedOverride.AppliedById.HasValue && oldRelatedOverride.AppliedDate.HasValue) { var oldAppliedUser = (from x in oldUsers where x.Id == oldRelatedOverride.AppliedById select x).FirstOrDefault(); irs.AppliedById = (from x in newUsers where x.UserName == oldAppliedUser.UserName select x).FirstOrDefault().Id; irs.AppliedDate = oldRelatedOverride.AppliedDate; } else { String message = String.Format("Issue '{0}': Related override '{1}' was marked as applied, but user or date was not set!", oldIssue.Id, oldRelatedOverride.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Removed = oldRelatedOverride.Removed; if (irs.Removed) { if (oldRelatedOverride.RemovedById.HasValue && oldRelatedOverride.RemovedDate.HasValue) { var oldRemovedUser = (from x in oldUsers where x.Id == oldRelatedOverride.RemovedById select x).FirstOrDefault(); irs.RemovedById = (from x in newUsers where x.UserName == oldRemovedUser.UserName select x).FirstOrDefault().Id; irs.RemovedDate = oldRelatedOverride.RemovedDate; } else { String message = String.Format("Issue '{0}': Related override '{1}' was marked as removed, but user or date was not set!", oldIssue.Id, oldRelatedOverride.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedOverride.Notes; irs.TargetRemovalDate = oldRelatedOverride.TargetRemovalDate; mCee.IssueRelatedOverrides.AddObject(irs); newIssueRelatedOverrides.Add(irs); } #endregion #region Related MechanicalEquipment foreach (var oldRelatedMechanicalEquipment in oldIssue.RelatedMechEquipments) { IssueRelatedMechanicalEquipment irs = new IssueRelatedMechanicalEquipment(); irs.IssueId = oldIssue.Id; irs.MechanicalEquipmentId = oldRelatedMechanicalEquipment.MechEquipment.Id; irs.Implemented = oldRelatedMechanicalEquipment.Implemented; if (irs.Implemented) { if (oldRelatedMechanicalEquipment.ImplementedBy.HasValue && oldRelatedMechanicalEquipment.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedMechanicalEquipment.ImplementedBy select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedMechanicalEquipment.ImplementedDate; } else { String message = String.Format("Issue '{0}': Related MechanicalEquipment '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedMechanicalEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Tested = oldRelatedMechanicalEquipment.Tested; if (irs.Tested) { if (oldRelatedMechanicalEquipment.TestedBy.HasValue && oldRelatedMechanicalEquipment.TestedDate.HasValue) { var oldTestedUser = (from x in oldUsers where x.Id == oldRelatedMechanicalEquipment.TestedBy select x).FirstOrDefault(); irs.TestedById = (from x in newUsers where x.UserName == oldTestedUser.UserName select x).FirstOrDefault().Id; irs.TestedDate = oldRelatedMechanicalEquipment.TestedDate; } else { String message = String.Format("Issue '{0}': Related MechanicalEquipment '{1}' was marked as tested, but user or date was not set!", oldIssue.Id, oldRelatedMechanicalEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedMechanicalEquipment.Notes; mCee.IssueRelatedMechanicalEquipments.AddObject(irs); newIssueRelatedMechanicalEquipments.Add(irs); } #endregion #region Related ElectricalEquipment foreach (var oldRelatedElectricalEquipment in oldIssue.RelatedElectricals) { IssueRelatedElectricalEquipment irs = new IssueRelatedElectricalEquipment(); irs.IssueId = oldIssue.Id; irs.ElectricalEquipmentId = oldRelatedElectricalEquipment.ElectricalEquipmentId; irs.Implemented = oldRelatedElectricalEquipment.Implemented; if (irs.Implemented) { if (oldRelatedElectricalEquipment.ImplementedBy.HasValue && oldRelatedElectricalEquipment.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedElectricalEquipment.ImplementedBy select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedElectricalEquipment.ImplementedDate; } else { String message = String.Format("Issue '{0}': Related ElectricalEquipment '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedElectricalEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Tested = oldRelatedElectricalEquipment.Tested; if (irs.Tested) { if (oldRelatedElectricalEquipment.TestedBy.HasValue && oldRelatedElectricalEquipment.TestedDate.HasValue) { var oldTestedUser = (from x in oldUsers where x.Id == oldRelatedElectricalEquipment.TestedBy select x).FirstOrDefault(); irs.TestedById = (from x in newUsers where x.UserName == oldTestedUser.UserName select x).FirstOrDefault().Id; irs.TestedDate = oldRelatedElectricalEquipment.TestedDate; } else { String message = String.Format("Issue '{0}': Related ElectricalEquipment '{1}' was marked as tested, but user or date was not set!", oldIssue.Id, oldRelatedElectricalEquipment.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedElectricalEquipment.Notes; mCee.IssueRelatedElectricalEquipments.AddObject(irs); newIssueRelatedElectricalEquipments.Add(irs); } #endregion #region Related Document foreach (var oldRelatedDocument in oldIssue.RelatedDocuments) { IssueRelatedDocument irs = new IssueRelatedDocument(); irs.IssueId = oldIssue.Id; var existingDocument = (from x in newDocuments where x.Id == oldRelatedDocument.DocumentId select x).FirstOrDefault(); if (existingDocument == null) { String message = String.Format("Issue '{0}': Related DocumentId '{1}' does not exist in the database!", oldIssue.Id, oldRelatedDocument.DocumentId); mForm.AddMessage(MessageType.Error, message); continue; ; } irs.DocumentId = existingDocument.Id; irs.Documented = oldRelatedDocument.Documented; if (irs.Documented) { if (oldRelatedDocument.DocumentedById.HasValue && oldRelatedDocument.DocumentedDate.HasValue) { var oldDocumentedUser = (from x in oldUsers where x.Id == oldRelatedDocument.DocumentedById select x).FirstOrDefault(); irs.DocumentedById = (from x in newUsers where x.UserName == oldDocumentedUser.UserName select x).FirstOrDefault().Id; irs.DocumentedDate = oldRelatedDocument.DocumentedDate; } else { String message = String.Format("Issue '{0}': Related Document '{1}' was marked as documented, but user or date was not set!", oldIssue.Id, irs.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedDocument.Notes; mCee.IssueRelatedDocuments.AddObject(irs); newIssueRelatedDocuments.Add(irs); } #endregion #region Related Issue Files foreach (var oldIssueFile in oldIssue.IssueFiles) { CmsEquipmentDatabase.CmsWebService.IssueFile irs = new CmsEquipmentDatabase.CmsWebService.IssueFile(); irs.IssueId = oldIssue.Id; irs.Filename = oldIssueFile.Filename; irs.DateUploaded = oldIssueFile.DateUploaded; var oldUploadedUser = (from x in oldUsers where x.Id == oldIssueFile.UploadedById select x).FirstOrDefault(); irs.UploadedById = (from x in newUsers where x.UserName == oldUploadedUser.UserName select x).FirstOrDefault().Id; irs.Description = oldIssueFile.Description; irs.Path = oldIssueFile.Path; irs.AttachmentTypeId = notSpecifiedAttachmentType; mCee.IssueFiles.AddObject(irs); newIssueFiles.Add(irs); } #endregion #region Related Issues foreach (var oldRelatedIssue in oldIssue.RelatedIssues) { IssueRelatedIssue irs = new IssueRelatedIssue(); irs.IssueId = oldIssue.Id; irs.RelatedIssueId = oldRelatedIssue.RelatedIssueId; mCee.IssueRelatedIssues.AddObject(irs); } #endregion #region Related Action foreach (var oldRelatedAction in oldIssue.RelatedActions) { IssueRelatedAction irs = new IssueRelatedAction(); irs.IssueId = oldIssue.Id; var oldInitiatedUser = (from x in oldUsers where x.Id == oldRelatedAction.InitiatedBy select x).FirstOrDefault(); irs.InitiatedById = (from x in newUsers where x.UserName == oldInitiatedUser.UserName select x).FirstOrDefault().Id; irs.InitiatedDate = oldRelatedAction.InitiatedDate; irs.RequiredDate = oldRelatedAction.RequiredDate; var oldAssignedToUser = (from x in oldUsers where x.Id == oldRelatedAction.AssignedTo select x).FirstOrDefault(); if (oldAssignedToUser != null) { irs.AssignedToId = (from x in newUsers where x.UserName == oldAssignedToUser.UserName select x).FirstOrDefault().Id; } irs.Implemented = oldRelatedAction.Implemented; if (irs.Implemented) { if (oldRelatedAction.ImplementedBy.HasValue && oldRelatedAction.ImplementedDate.HasValue) { var oldImplementedUser = (from x in oldUsers where x.Id == oldRelatedAction.ImplementedBy select x).FirstOrDefault(); irs.ImplementedById = (from x in newUsers where x.UserName == oldImplementedUser.UserName select x).FirstOrDefault().Id; irs.ImplementedDate = oldRelatedAction.ImplementedDate; } else { String message = String.Format("Issue '{0}': Action '{1}' was marked as implemented, but user or date was not set!", oldIssue.Id, oldRelatedAction.Id); mForm.AddMessage(MessageType.Error, message); } } irs.Notes = oldRelatedAction.Notes; irs.Description = oldRelatedAction.Description; mCee.IssueRelatedActions.AddObject(irs); } #endregion #region Issue Risk #region Initial Finance if (oldIssue.RiskRatingFinance.HasValue) { var oldRiskRatingFinance = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.RiskRatingFinance.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = initialRiskTypeId; newRisk.CategoryId = financeCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingFinance.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == financeCategoryId && x.RiskTypeId == initialRiskTypeId && x.ConsequenceRatingId == oldRiskRatingFinance.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingFinance.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Initial HSLP if (oldIssue.RiskRatingHSLP.HasValue) { var oldRiskRatingHSLP = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.RiskRatingHSLP.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = initialRiskTypeId; newRisk.CategoryId = hslpCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingHSLP.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == hslpCategoryId && x.RiskTypeId == initialRiskTypeId && x.ConsequenceRatingId == oldRiskRatingHSLP.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingHSLP.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Initial Environment if (oldIssue.RiskRatingEnvironment.HasValue) { var oldRiskRatingEnvironment = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.RiskRatingEnvironment.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = initialRiskTypeId; newRisk.CategoryId = environmentCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingEnvironment.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == environmentCategoryId && x.RiskTypeId == initialRiskTypeId && x.ConsequenceRatingId == oldRiskRatingEnvironment.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingEnvironment.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Initial Community if (oldIssue.RiskRatingCommunity.HasValue) { var oldRiskRatingCommunity = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.RiskRatingCommunity.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = initialRiskTypeId; newRisk.CategoryId = communityCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingCommunity.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == communityCategoryId && x.RiskTypeId == initialRiskTypeId && x.ConsequenceRatingId == oldRiskRatingCommunity.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingCommunity.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Initial Operational if (oldIssue.RiskRatingOperational.HasValue) { var oldRiskRatingOperational = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.RiskRatingOperational.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = initialRiskTypeId; newRisk.CategoryId = operationalCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingOperational.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == operationalCategoryId && x.RiskTypeId == initialRiskTypeId && x.ConsequenceRatingId == oldRiskRatingOperational.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingOperational.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Final Finance if (oldIssue.FinalRiskRatingFinance.HasValue) { var oldRiskRatingFinance = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.FinalRiskRatingFinance.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = finalRiskTypeId; newRisk.CategoryId = financeCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingFinance.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == financeCategoryId && x.RiskTypeId == finalRiskTypeId && x.ConsequenceRatingId == oldRiskRatingFinance.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingFinance.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Final HSLP if (oldIssue.FinalRiskRatingHSLP.HasValue) { var oldRiskRatingHSLP = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.FinalRiskRatingHSLP.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = finalRiskTypeId; newRisk.CategoryId = hslpCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingHSLP.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == hslpCategoryId && x.RiskTypeId == finalRiskTypeId && x.ConsequenceRatingId == oldRiskRatingHSLP.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingHSLP.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Final Environment if (oldIssue.FinalRiskRatingEnvironment.HasValue) { var oldRiskRatingEnvironment = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.FinalRiskRatingEnvironment.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = finalRiskTypeId; newRisk.CategoryId = environmentCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingEnvironment.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == environmentCategoryId && x.RiskTypeId == finalRiskTypeId && x.ConsequenceRatingId == oldRiskRatingEnvironment.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingEnvironment.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Final Community if (oldIssue.FinalRiskRatingCommunity.HasValue) { var oldRiskRatingCommunity = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.FinalRiskRatingCommunity.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = finalRiskTypeId; newRisk.CategoryId = communityCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingCommunity.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == communityCategoryId && x.RiskTypeId == finalRiskTypeId && x.ConsequenceRatingId == oldRiskRatingCommunity.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingCommunity.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #region Final Operational if (oldIssue.FinalRiskRatingOperational.HasValue) { var oldRiskRatingOperational = (from x in oldRiskMatrixes where x.RiskRating == oldIssue.FinalRiskRatingOperational.Value select x).FirstOrDefault(); var newRisk = new IssueRisk(); newRisk.IssueId = oldIssue.Id; newRisk.RiskTypeId = finalRiskTypeId; newRisk.CategoryId = operationalCategoryId; newRisk.RiskLikelihoodId = oldRiskRatingOperational.LikelihoodId; var issueConsequence = (from x in newIssueRiskConsequences where x.CategoryId == operationalCategoryId && x.RiskTypeId == finalRiskTypeId && x.ConsequenceRatingId == oldRiskRatingOperational.ConsequenceId select x).FirstOrDefault(); newRisk.ConsequenceId = issueConsequence.Id; var riskMatrix = (from x in newIssueRiskMatrices where x.ConsequenceId == issueConsequence.ConsequenceRatingId && x.LikelihoodId == oldRiskRatingOperational.LikelihoodId select x).FirstOrDefault(); newRisk.RiskMatrixId = riskMatrix.Id; mCee.IssueRisks.AddObject(newRisk); newIssueRisks.Add(newRisk); } #endregion #endregion #region IssueResponse foreach (var oldIssueResponse in oldIssue.Responses) { IssueResponse ir = new IssueResponse(); ir.IssueId = oldIssue.Id; ir.ResponseText = oldIssueResponse.ResponseText; ir.Date = oldIssueResponse.Date; var oldStatus = (from x in oldStatuses where x.Id == oldIssueResponse.StatusId select x).FirstOrDefault(); var status = (from x in newIssueStatuses where x.Name == oldStatus.Name select x).FirstOrDefault(); ir.StatusId = status.Id; var oldPriority = (from x in oldPriorities where x.Id == oldIssueResponse.PriorityId select x).FirstOrDefault(); var priority = (from x in newIssuePriorities where x.Name == oldPriority.Name select x).FirstOrDefault(); ir.PriorityId = priority.Id; var oldUser = (from x in oldUsers where x.Id == oldIssueResponse.UserId select x).FirstOrDefault(); var newUser = (from x in newUsers where x.UserName == oldUser.UserName select x).FirstOrDefault(); ir.UserId = newUser.Id; var oldAssignedToUser = (from x in oldUsers where x.Id == oldIssueResponse.AssignedToId select x).FirstOrDefault(); var newAssignedToUser = (from x in newUsers where x.UserName == oldAssignedToUser.UserName select x).FirstOrDefault(); ir.AssignedToId = newAssignedToUser.Id; if (oldIssueResponse.DesignedById.HasValue) { var oldDesignedByUser2 = (from x in oldUsers where x.Id == oldIssueResponse.DesignedById select x).FirstOrDefault(); var newDesignedByUser = (from x in newUsers where x.UserName == oldDesignedByUser2.UserName select x).FirstOrDefault(); ir.DesignedById = newDesignedByUser.Id; } mCee.IssueResponses.AddObject(ir); } #endregion } catch (Exception ex) { string message = String.Format("Issue #{0}: {1} Stack Trace: {2}, Inner Exeption {3}", oldIssue.Id, ex.Message, ex.StackTrace, ex.InnerException == null ? String.Empty : ex.InnerException.Message); mForm.AddMessage(MessageType.Error, message); return; } } mCee.SaveChanges(); mCee.AcceptAllChanges(); transaction.Complete(); } }
public static string GetIssueAreaDes(IssueArea status) { return(EnumDescription.GetFieldText(status)); }
private void OkButtonHander(object parameter) { if (CanExecuteOkButtonHandler(parameter)) { var copy = new Issue { IsActive = mIssue.IsActive, RestrictedContent = mIssue.RestrictedContent, InitiatedById = CMS.User.Id, InitiatedDate = DateTime.Now, ModifiedById = CMS.User.Id, ModifiedDate = DateTime.Now }; foreach (IssueSubType option in Options) { if (option.Checked) { switch (option.Name) { case "Name": copy.Name = mIssue.Name; break; case "Description": copy.Description = mIssue.Description; break; case "Reason": copy.Reason = mIssue.Reason; break; case "RequestedBy": copy.RequestedBy = mIssue.RequestedBy; break; case "KeyStakeholder": copy.KeyStakeholder = mIssue.KeyStakeholder; break; case "Solution": copy.SuggestedSolution = mIssue.SuggestedSolution; break; case "IssueType": copy.IssueTypeId = mIssue.IssueTypeId; break; case "IssueSubType": copy.IssueSubTypeId = mIssue.IssueSubTypeId; break; case "Classification": copy.IssueClassificationId = mIssue.IssueClassificationId; break; case "Priority": copy.IssuePriorityId = mIssue.IssuePriorityId; break; case "Categories": copy.IssueAssignedCategories = new List<IssueAssignedCategory>(); List<int> catIds = new List<int>(); foreach (IssueAssignedCategory assignedCategory in mIssue.IssueAssignedCategories) { if (!catIds.Contains(assignedCategory.IssueCategoryId)) { catIds.Add(assignedCategory.IssueCategoryId); IssueCategory issueCategory = (from x in CMS.Cache.IssueCategories where x.Id == assignedCategory.IssueCategoryId select x).FirstOrDefault(); if (issueCategory == null) { continue; } var issueAssignedCategory = new IssueAssignedCategory { IssueCategory = issueCategory, IssueCategoryId = issueCategory.Id }; copy.IssueAssignedCategories.Add(issueAssignedCategory); } } break; case "Areas": copy.IssueAreas = new List<IssueArea>(); foreach (IssueArea issueArea in mIssue.IssueAreas) { var area = new IssueArea { AreaId = issueArea.AreaId }; copy.IssueAreas.Add(area); } break; case "Overrides": copy.IssueRelatedOverrides = new List<IssueRelatedOverride>(); CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetIssueRelatedOverrideCompleted += (s, e) => { foreach (IssueRelatedOverride relatedOverride in e.Result) { var issueRelatedOverrideoverride = new IssueRelatedOverride { InterlockId = relatedOverride.InterlockId }; copy.IssueRelatedOverrides.Add(issueRelatedOverrideoverride); } View.CopiedIssue = copy; View.DialogResult = true; }; cmsWebServiceClient.GetIssueRelatedOverrideAsync(mIssue.Id); break; } } } View.CopiedIssue = copy; View.DialogResult = true; } }