示例#1
0
        private void SaveIssueAttachments(Issue issue, CmsEntities cee, int userId)
        {
            log.Verbose("SaveIssueAttachments()");
            foreach (IssueFile issueFile in issue.IssueFiles)
            {
                IssueFile existing = (from x in cee.IssueFiles
                                      where x.IssueId == issue.Id &&
                                            x.Filename == issueFile.Filename &&
                                            x.Path == issueFile.Path
                                      select x).FirstOrDefault();

                if (existing != null)
                {
                    existing.AttachmentTypeId = issueFile.AttachmentTypeId;
                    existing.Description = issueFile.Description;

                    if (existing.RestrictedContent != issueFile.RestrictedContent)
                    {
                        //Add Revision History
                        var issueResponse = new IssueResponse
                        {
                            IssueId = issue.Id,
                            UserId = userId,
                            PriorityId = issue.IssuePriorityId,
                            AssignedToId = issue.CurrentlyAssignedToId,
                            Date = DateTime.Now,
                            StatusId = issue.IssueStatusId
                        };

                        if (issueFile.RestrictedContent)
                        {
                            issueResponse.ResponseText = string.Format("Issue Attachment '{0}' marked as Restricted Content.", existing.Filename);
                        }
                        else
                        {
                            issueResponse.ResponseText = string.Format("Issue Attachment '{0}' Restricted Content reset.", existing.Filename);
                        }

                        cee.IssueResponses.Add(issueResponse);
                    }

                    existing.RestrictedContent = issueFile.RestrictedContent;
                }
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        private IssueResponse CreateIssueResponse(Issue issue, string responseText, bool isSystemMessage)
        {
            var newResponse = new IssueResponse
            {
                IssueId = issue.Id,
                UserId = issue.ModifiedById,
                PriorityId = issue.IssuePriorityId,
                AssignedToId = issue.CurrentlyAssignedToId,
                Date = DateTime.Now,
                StatusId = issue.IssueStatusId,
                ResponseText = responseText.Trim(),
                IsSystemMessage = isSystemMessage
            };

            return newResponse;
        }
示例#4
0
        public bool UnMarkIssueAsRestricted(int issueId, int userId)
        {
            using (var cee = new CmsEntities())
            {
                if (CanUserOpenRestrictedIssue(issueId, userId))
                {
                    Issue issue = (from x in cee.Issues where x.Id == issueId select x).FirstOrDefault();

                    if (issue != null)
                    {
                        issue.RestrictedContent = false;

                        var issueResponse = new IssueResponse
                        {
                            IssueId = issue.Id,
                            UserId = userId,
                            PriorityId = issue.IssuePriorityId,
                            AssignedToId = issue.CurrentlyAssignedToId,
                            Date = DateTime.Now,
                            StatusId = issue.IssueStatusId,
                            ResponseText = string.Format("Issue {0} Restricted Content reset.", issue.Id)
                        };

                        cee.IssueResponses.Add(issueResponse);
                    }
                    cee.SaveChanges();
                    return true;
                }
            }
            return false;
        }
示例#5
0
        public bool DeleteIssue(int issueId, int userId)
        {
            using (var cee = new CmsEntities())
            {
                Issue deleteCandidate = (from x in cee.Issues where x.Id == issueId select x).FirstOrDefault();

                if (deleteCandidate != null)
                {
                    deleteCandidate.IsActive = false;

                    var issueResponse = new IssueResponse
                    {
                        IssueId = deleteCandidate.Id,
                        UserId = userId,
                        PriorityId = deleteCandidate.IssuePriorityId,
                        AssignedToId = deleteCandidate.CurrentlyAssignedToId,
                        Date = DateTime.Now,
                        StatusId = deleteCandidate.IssueStatusId,
                        ResponseText = string.Format("Issue {0} changed to InActive.", deleteCandidate.Id)
                    };

                    cee.IssueResponses.Add(issueResponse);

                    cee.SaveChanges();
                    return true;
                }

                return false;
            }
        }
示例#6
0
        private bool BuildAndValidateIssue(IssueDataAdapter adapter, int i, Issue issue)
        {
            //NOT NULLs...
            issue.ModifiedDate = DateTime.Now;
            issue.ModifiedById = MetaData.UserId;
            issue.IsActive = true;

            //InitiationDate
            DateTime dt;
            if (!string.IsNullOrEmpty(adapter.InitiationDate) && DateTime.TryParse(adapter.InitiationDate, out dt))
            {

                if (dt.Date > DateTime.Now.Date)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildDateCannotBeInFutureInExcelMessage("InitiatedDate", adapter.InitiationDate, adapter.RowNumber)));
                    return true;
                }

                issue.InitiatedDate = dt;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotInValidFormatInExcelMessage("InitiatedDate", adapter.InitiationDate, adapter.RowNumber)));
                return true;
            }

            //InitiatedBy
            if (!string.IsNullOrEmpty(adapter.InitiatedBy))
            {
                User user = GetUserFromText(adapter.InitiatedBy);
                if (user != null)
                {
                    issue.InitiatedById = user.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("InitiatedBy", adapter.InitiatedBy, adapter.RowNumber)));
                    return true;
                }
            }

            //ProjectSupervisor
            if (!string.IsNullOrEmpty(adapter.ProjectSupervisor))
            {
                User user = GetUserFromText(adapter.ProjectSupervisor);
                if (user != null)
                {
                    issue.ProjectSupervisorId = user.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("ProjectSupervisor", adapter.ProjectSupervisor, adapter.RowNumber)));
                    return true;
                }
            }

            //AssignedTo (OriginallyAssignedToId is set to the same)
            if (!string.IsNullOrEmpty(adapter.AssignedTo))
            {
                User user = GetUserFromText(adapter.AssignedTo);
                if (user != null)
                {
                    issue.CurrentlyAssignedToId = user.Id;
                    issue.OriginallyAssignedToId = user.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("CurrentlyAssignedTo", adapter.AssignedTo, adapter.RowNumber)));
                    return true;
                }
            }

            //IssueType
            IssueType issueType = (from x in mExistingIssueTypes where x.Name.Equals(adapter.IssueType, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

            if (issueType != null)
            {
                issue.IssueTypeId = issueType.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("IssueType", adapter.IssueType, adapter.RowNumber)));
                return true;
            }

            //IssueSUBType
            IssueSubType issueSubType = (from x in mExistingIssueSubTypes where x.Name.Equals(adapter.IssueSubType, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

            if (issueSubType != null)
            {
                issue.IssueSubTypeId = issueSubType.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("IssueSubType", adapter.IssueType, adapter.RowNumber)));
                return true;
            }

            //IssueClassification
            if (!string.IsNullOrEmpty(adapter.Classification))
            {
                IssueClassification classification = (from x in mExistingClassifications where String.Compare(x.Name, adapter.Classification, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                if (classification != null)
                {
                    issue.IssueClassificationId = classification.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Classification", adapter.Classification, adapter.RowNumber)));
                    return true;
                }
            }

            //IssueCategory
            if (!string.IsNullOrEmpty(adapter.Categories))
            {
                string[] categories = adapter.Categories.Split(new[] { ',' });

                foreach (string adapterCategoryName in categories)
                {
                    IssueCategory issueCategory = (from x in mExistingCategories where String.Compare(x.Name, adapterCategoryName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

                    if (issueCategory != null)
                    {
                        issue.IssueAssignedCategories.Add(new IssueAssignedCategory { Issue = issue, IssueCategoryId = issueCategory.Id });
                        issue.IssueApprovals.Add(new IssueApproval { Issue = issue, IssueCategoryId = issueCategory.Id });
                        issue.IssueCloseouts.Add(new IssueCloseout { Issue = issue, IssueCategoryId = issueCategory.Id });
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Category", adapterCategoryName, adapter.RowNumber)));
                        return true;
                    }
                }
            }

            //IssuePriority
            if (!string.IsNullOrEmpty(adapter.Priority))
            {
                IssuePriority priority = (from x in mExistingPriorities where String.Compare(x.Name, adapter.Priority, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                if (priority != null)
                {
                    issue.IssuePriorityId = priority.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Priority", adapter.Priority, adapter.RowNumber)));
                    return true;
                }
            }

            //IssueStatus
            if (!string.IsNullOrEmpty(adapter.Status))
            {
                IssueStatus status = (from x in mExistingStatuses where String.Compare(x.Name, adapter.Status, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                if (status != null)
                {
                    issue.IssueStatusId = status.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Status", adapter.Status, adapter.RowNumber)));
                    return true;
                }
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Status", adapter.Status, adapter.RowNumber)));
                return true;
            }

            //Areas
            if (!string.IsNullOrEmpty(adapter.AreaNumbers))
            {
                string[] areas = adapter.AreaNumbers.Split(new[] { ',' });

                foreach (string number in areas)
                {
                    int areaNumber = -1;

                    if (int.TryParse(number, out areaNumber))
                    {

                        Area area = (from x in Cee.Areas where x.AreaNumber == areaNumber select x).FirstOrDefault();

                        if (area != null)
                        {
                            issue.IssueAreas.Add(new IssueArea {Issue = issue, AreaId = area.Id});
                        }
                        else
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Areas", adapter.AreaNumbers, adapter.RowNumber)));
                            return true;
                        }
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Areas", number, adapter.RowNumber)));
                    }
                }
            }

            //Budgeted
            bool result;
            if (Boolean.TryParse(adapter.Budgeted, out result))
            {
                issue.IssueTracking.Budgeted = result;
            }
            else
            {
                if (String.Compare(adapter.Budgeted, "Yes", true, CultureInfo.CurrentCulture) == 0)
                {
                    issue.IssueTracking.Budgeted = true;
                }
                else
                {
                    issue.IssueTracking.Budgeted = false;
                }
            }

            //EstimatedCost
            if (!string.IsNullOrEmpty(adapter.EstimatedCost))
            {
                double dr;
                if (Double.TryParse(adapter.EstimatedCost, out dr))
                {
                    issue.IssueTracking.EstimatedCost = dr;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotInValidFormatInExcelMessage("EstimatedCost", adapter.EstimatedCost, adapter.RowNumber)));
                    return true;
                }
            }

            //Effort
            if (!string.IsNullOrEmpty(adapter.Effort))
            {
                int effort;
                if (Int32.TryParse(adapter.Effort, out effort))
                {
                    issue.IssueTracking.Effort = effort;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotInValidFormatInExcelMessage("Effort", adapter.Effort, adapter.RowNumber)));
                    return true;
                }
            }

            //Reward
            if (!string.IsNullOrEmpty(adapter.Reward))
            {
                int reward;
                if (Int32.TryParse(adapter.Reward, out reward))
                {
                    issue.IssueTracking.Return = reward;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotInValidFormatInExcelMessage("Reward", adapter.Reward, adapter.RowNumber)));
                    return true;
                }
            }

            //ScopeUser
            if (!string.IsNullOrEmpty(adapter.ScopeUser))
            {
                User user = GetUserFromText(adapter.ScopeUser);
                if (user != null)
                {
                    issue.IssueTracking.ScopedUserId = user.Id;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("ScopeUser", adapter.ScopeUser, adapter.RowNumber)));
                    return true;
                }
            }

            //Response
            if (!string.IsNullOrEmpty(adapter.RevisionHistory))
            {
                IssueResponse ir = new IssueResponse
                                       {
                                           AssignedToId = issue.CurrentlyAssignedToId,
                                           UserId = MetaData.UserId,
                                           Date = DateTime.Now,
                                           ResponseText = adapter.RevisionHistory,
                                           PriorityId = issue.IssuePriorityId,
                                           StatusId = issue.IssueStatusId,
                                           Issue = issue
                                       };

                issue.IssueResponses.Add(ir);
            }

            return false;
        }
        private void DeleteIssueIssueRelatedOverrides(ControlSystem controlSystem, Interlock interlock, CmsEntities cee, int userId)
        {
            const string Date24HTimestamp = "dd/MM/yyyy HH:mm";

            var issueRelatedOverrides = (from x in cee.IssueRelatedOverrides.Include("Issue") where x.InterlockId == interlock.Id select x).ToList();

            var user = (from x in cee.Users where x.Id == userId select x).FirstOrDefault();

            foreach (var relatedOverride in issueRelatedOverrides)
            {
                var appliedByUser = (from x in cee.Users where x.Id == relatedOverride.AppliedById select x).FirstOrDefault();
                var responseText = string.Format("Related Override {0}-{1}-{2} deleted from Control Module {3} by {4} on {5}. Override Applied on {6} by {7}. Override Removed on {8} by {4}", interlock.InterlockType.Name, interlock.Number, interlock.Cause, controlSystem.Name, user.FirstLastName, DateTime.Now.ToString(Date24HTimestamp), relatedOverride.AppliedDate, appliedByUser.FirstLastName, DateTime.Now.ToString(Date24HTimestamp));

                var issueResponse = new IssueResponse
                {
                    IssueId = relatedOverride.IssueId,
                    PriorityId = relatedOverride.Issue.IssuePriorityId,
                    UserId = user.Id,
                    StatusId = relatedOverride.Issue.IssueStatusId,
                    AssignedToId = relatedOverride.Issue.CurrentlyAssignedToId,
                    Date = DateTime.Now,
                    ResponseText = responseText
                };

                cee.IssueRelatedOverrides.Remove(relatedOverride);
                cee.IssueResponses.Add(issueResponse);
            }
        }