public void AddSupervisorsToApprovals()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (CmsEntities cee = new CmsEntities(120, mConnectCMS))
                {
                    var supervisorCategory = (from x in cee.IssueCategories where x.Code == "SUPERVISOR" select x).FirstOrDefault();
                    var pcsAdminUser = (from x in cee.Users where x.UserName == "pcsadmin" select x).FirstOrDefault();

                    var issues = (from x in cee.Issues orderby x.Id select x).ToList();

                    foreach (var issue in issues)
                    {
                        Console.Out.WriteLine("Processing issue {0}", issue.Id);

                        Issue issue1 = issue;
                        var hasAnyApprovalsChecked = (from x in cee.IssueApprovals
                                              where x.IssueId == issue1.Id
                                                    && x.IssueCategoryId != supervisorCategory.Id
                                                    && x.Approved
                                              select x).Any();

                        var hasSupervisor = (from x in cee.IssueApprovals
                                             where x.IssueId == issue1.Id
                                             && x.IssueCategoryId == supervisorCategory.Id
                                             select x).FirstOrDefault();

                        if (hasSupervisor == null && hasAnyApprovalsChecked)
                        {
                            var newIssueApproval = new IssueApproval
                                {
                                    IssueId = issue.Id,
                                    IssueCategoryId = supervisorCategory.Id,
                                    Approved = true,
                                    Approver = pcsAdminUser,
                                    Date = DateTime.Now
                                };

                            cee.IssueApprovals.Add(newIssueApproval);
                            Console.Out.WriteLine("Added Supervisor for IssueApproval on issue {0}", issue.Id);

                        }
                    }

                    cee.SaveChanges();

                    transaction.Complete();

                    Console.Out.WriteLine("Transaction Complete");
                    Console.ReadLine();
                }
            }
        }
Example #2
0
        private void OkButtonHander(object parameter)
        {
            if (AreAllValid())
            {
                View.OKButton.IsEnabled = false;
                View.CancelButton.IsEnabled = false;

                mIssue.OriginallyAssignedToUser = null;

                mIssue.ModifiedByUser = null;
                mIssue.IssueType = null;
                mIssue.IssueSubType = null;
                mIssue.IssuePriority = null;
                mIssue.IssueStatus = null;
                mIssue.InitiatedByUser = null;
                mIssue.ProjectSupervisorUser = null;

                if (!mIsCopy)
                {
                    mIssue.IsActive = true;
                }

                //We are creating new issue so set the default users and dates
                mIssue.ModifiedById = CMS.User.Id;
                mIssue.ModifiedDate = DateTime.Now;

                mIssue.IssueApprovals = new List<IssueApproval>();
                mIssue.IssueDistributionUsers = new List<IssueDistributionUser> { new IssueDistributionUser { AllowDeletion = true, UserId = CMS.User.Id } };

                //Add Issue Approvals
                IssueDistributionUser existingDistUser;

                List<int> catIds = new List<int>();
                foreach (var issueAssignedCategory in mIssue.IssueAssignedCategories)
                {
                    if (!catIds.Contains(issueAssignedCategory.IssueCategoryId))
                    {
                        catIds.Add(issueAssignedCategory.IssueCategoryId);

                        var issueApproval = new IssueApproval { IssueCategoryId = issueAssignedCategory.IssueCategoryId };

                        if (issueAssignedCategory.IssueCategory != null)
                        {
                            foreach (var issueCategoryUser in issueAssignedCategory.IssueCategory.IssueCategoryUsers)
                            {
                                existingDistUser = (from x in mIssue.IssueDistributionUsers where x.UserId == issueCategoryUser.UserId select x).FirstOrDefault();
                                if (existingDistUser == null)
                                {
                                    mIssue.IssueDistributionUsers.Add(new IssueDistributionUser { AllowDeletion = false, UserId = issueCategoryUser.UserId });
                                }
                                else
                                {
                                    //Make sure this one is not editable
                                    existingDistUser.AllowDeletion = false;
                                }
                            }

                            issueAssignedCategory.Issue = null;
                        }

                        issueAssignedCategory.IssueCategory = null;

                        mIssue.IssueApprovals.Add(issueApproval);
                    }
                }

                //Add AssignedToUser to Distribution List
                existingDistUser = (from x in mIssue.IssueDistributionUsers where x.UserId == CurrentlyAssignedToUser.Id select x).FirstOrDefault();
                if (existingDistUser == null)
                {
                    mIssue.IssueDistributionUsers.Add(new IssueDistributionUser { AllowDeletion = false, UserId = CurrentlyAssignedToUser.Id });
                }
                mIssue.CurrentlyAssignedToUser = null;

                mIssue.InitiatedById = CMS.User.Id;
                mIssue.InitiatedDate = DateTime.Now;
                string waitingPreApprovalCode = CommonUtils.IssueStatusCode.WaitingPreApproval.ToString().ToLower();

                IssueStatus openStatus = (from x in CMS.Cache.IssueStatuses
                                          where x.Code.ToLower() == waitingPreApprovalCode
                                          select x).FirstOrDefault();

                if (openStatus != null) { mIssue.IssueStatusId = openStatus.Id; }

                UpdateCloseouts();

                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                //Save Issue
                cmsWebServiceClient.SaveIssueCompleted +=
                    (s2, e2) =>
                    {
                        if (e2.Result.HasErrors)
                        {
                            View.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("Save Failed", e2.Result.ServerErrorMessages));
                        }
                        else
                        {
                            View.QuickIssue = e2.Result.EntityResult;
                            mIssue.Id = e2.Result.EntityResult.Id;
                            mIssue.IssueStatus = (from x in mIssueStatuses where x.Id == mIssue.IssueStatusId select x).FirstOrDefault();
                            mIssue.IssuePriority = (from x in mIssuePriorities where x.Id == mIssue.IssuePriorityId select x).FirstOrDefault();
                            mIssue.IssueType = (from x in mIssueTypes where x.Id == mIssue.IssueTypeId select x).FirstOrDefault();
                            View.Issue = mIssue;

                            View.DialogResult = true;
                            View.Close();

                            EventAggregator.GetEvent<PrismEvents.OpenTabPrismEvent>().Publish(View.QuickIssue);
                            EventAggregator.GetEvent<PrismEvents.RefreshNavigationEvent>().Publish(new QuickIssue());

                        }
                        View.OKButton.IsEnabled = true;
                        View.CancelButton.IsEnabled = true;
                    };

                foreach (var risks in mIssue.IssueRisks)
                {
                    risks.Issue = null;
                    risks.IssueRiskType = null;
                    risks.IssueRiskCategory = null;
                    risks.IssueRiskLikelihood = null;
                    risks.IssueRiskConsequence = null;
                    risks.IssueRiskMatrix = null;
                }

                foreach (var stakeholder in mIssue.IssueRelatedKeyStakeholders)
                {
                    stakeholder.Role = null;
                }

                mIssue.ModifiedByUser = CMS.User;
                cmsWebServiceClient.SaveIssueAsync(mIssue, CMS.User);
            }
        }
        private void UpdateApprovals()
        {
            foreach (IssueAssignedCategory issueAssignedCategory in IssueAssignedCategories)
            {
                IssueApproval existinAproval = (from x in mIssue.IssueApprovals
                                                where x.IssueId == mIssue.Id && x.IssueCategoryId == issueAssignedCategory.IssueCategoryId
                                                select x).FirstOrDefault();
                if (existinAproval == null)
                {
                    var issueApproval = new IssueApproval
                    {
                        IssueId = mIssue.Id,
                        IssueCategoryId = issueAssignedCategory.IssueCategoryId,
                        IssueCategory = issueAssignedCategory.IssueCategory,
                    };

                    mIssue.IssueApprovals.Add(issueApproval);
                }
            }

            //Remove not needed Approvals (Approvals that are not approved and category was removed for them)
            var approvalsToRemove = new List<IssueApproval>();
            foreach (IssueApproval issueApproval in mIssue.IssueApprovals)
            {
                if (issueApproval.Approved == false)
                {
                    IssueAssignedCategory existInIssueAssignedCategories = (from x in IssueAssignedCategories where x.IssueCategoryId == issueApproval.IssueCategoryId select x).FirstOrDefault();
                    if (existInIssueAssignedCategories == null)
                    {
                        approvalsToRemove.Add(issueApproval);
                    }
                }
            }

            approvalsToRemove.ForEach(x => mIssue.IssueApprovals.Remove(x));

            View.IssuesPanel.ApprovalsControl.ViewModel.RaisePropertyChanged("IssueApprovals");
        }
Example #4
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();
            }
        }
Example #5
0
        private IssueApproval AddSupervisorApproval()
        {
            IssueCategory category = (from x in CMS.Cache.IssueCategories where x.Code == Supervisor select x).FirstOrDefault();

            IssueApproval preApproval = new IssueApproval
                {
                    IssueId = mIssue.Id,
                    IssueCategoryId = category.Id,
                    IssueCategory = category,
                    ApproverId = null
                };

            mIssue.IssueApprovals.Insert(0, preApproval);
            return preApproval;
        }
Example #6
0
        private void SaveIssueApprovals(Issue issue, Issue originalIssue, CmsEntities cee)
        {
            log.Verbose("SaveIssueApprovals()");

            if (issue.IssueApprovals.Count == 0) return;

            int issueId = issue.Id;

            ////delete...
            cee.DeleteWhere<IssueApproval>(cee, x => x.IssueId == issue.Id);

            var ht = new Hashtable(); //for some reason we are sending back too many approvals - hack stop for now...

            cee.Configuration.AutoDetectChangesEnabled = false;
            foreach (IssueApproval approval in issue.IssueApprovals)
            {
                var newApproval = new IssueApproval();

                if (!ht.ContainsKey(approval.IssueCategoryId))
                {
                    ht.Add(approval.IssueCategoryId, approval.IssueCategoryId);

                    newApproval.IssueCategoryId = approval.IssueCategoryId;
                    newApproval.IssueId = issueId;

                    if (approval.Approver != null)
                    {
                        newApproval.ApproverId = approval.ApproverId;
                        newApproval.Approved = approval.Approved;
                        newApproval.Date = approval.Date;
                    }

                    originalIssue.IssueApprovals.Add(newApproval);
                }
            }

            //issue.IssueApprovals.Clear();

            cee.Configuration.AutoDetectChangesEnabled = true;
        }
Example #7
0
        private void UpdateData(IList<IssueDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            for (int i = 0; i < importData.Count; i++)
            {
                IssueDataAdapter adapter = importData[i];

                IList<string> ids = (from x in importData select x.ID).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.ID, ids, adapter.RowNumber))
                {
                    continue;
                }

                //NUMBER
                int issueIdInteger;
                if (!int.TryParse(adapter.ID, out issueIdInteger))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("ID '{0}' is not in a valid numeric format for Issue ID Type '{1}' at Row {2}", adapter.ID, adapter.Name, i + 1));
                    continue;
                }

                Issue dbIssue = (from x in Cee.Issues where x.Id == issueIdInteger select x).FirstOrDefault();
                if (dbIssue == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, BuildItemNameDoesNotExistInDbMessage(adapter.Name, adapter.RowNumber));
                    continue;
                }

                var issueTracking = (from x in Cee.IssueTrackings where x.Id == dbIssue.IssueTrackingId select x).FirstOrDefault();
                if (issueTracking == null)
                {
                    dbIssue.IssueTracking = new IssueTracking();
                }

                //NAME
                if (!string.IsNullOrEmpty(adapter.Name))
                {
                    if (adapter.Name.Length > 500)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.Name, 500, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.Name = adapter.Name.Trim();
                }

                //DESCRIPTION
                if (!string.IsNullOrEmpty(adapter.Description))
                {
                    if (adapter.Description.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.Description.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.Description = adapter.Description.Trim();
                }

                //REASON
                if (!string.IsNullOrEmpty(adapter.Reason))
                {
                    if (adapter.Reason.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.Reason.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.Reason = adapter.Reason.Trim();
                }

                //SUGGESTED SOLUTION
                if (!string.IsNullOrEmpty(adapter.SuggestedSolution))
                {
                    if (adapter.SuggestedSolution.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error,BuildPropertyTooLong(adapter.SuggestedSolution.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.SuggestedSolution = adapter.SuggestedSolution.Trim();
                }

                //REQUESTED BY
                if (!string.IsNullOrEmpty(adapter.RequestedBy))
                {
                    if (adapter.RequestedBy.Length > 50)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.RequestedBy, 50, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.RequestedBy = adapter.RequestedBy.Trim();
                }

                //ProjectSupervisor BY
                if (!string.IsNullOrEmpty(adapter.ProjectSupervisor))
                {
                    User user = GetUserFromText(adapter.ProjectSupervisor);
                    if (user != null)
                    {
                        dbIssue.ProjectSupervisorId = user.Id;
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildItemNotFoundInDatabaseMessage("ProjectSupervisor", adapter.ProjectSupervisor, adapter.RowNumber));
                        continue;
                    }
                }

                //INITIATED BY
                if (!string.IsNullOrEmpty(adapter.InitiatedBy))
                {
                    User user = GetUserFromText(adapter.InitiatedBy);
                    if (user != null)
                    {
                        dbIssue.InitiatedById = user.Id;
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error,BuildItemNotFoundInDatabaseMessage("InitiatedBy", adapter.InitiatedBy, adapter.RowNumber));
                        continue;
                    }
                }

                //ASSIGNED TO
                if (!string.IsNullOrEmpty(adapter.AssignedTo))
                {
                    User user = GetUserFromText(adapter.AssignedTo);
                    if (user != null)
                    {
                        dbIssue.CurrentlyAssignedToId = user.Id;
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildItemNotFoundInDatabaseMessage("AssignedTo", adapter.AssignedTo, adapter.RowNumber));
                        continue;
                    }
                }

                //INITIATIONDATE
                if (!string.IsNullOrEmpty(adapter.InitiationDate))
                {
                    DateTime dt;
                    if (DateTime.TryParse(adapter.InitiationDate, out dt))
                    {
                        if (dt.Date > DateTime.Now.Date)
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, BuildDateCannotBeInFutureInExcelMessage("InitiatedDate", adapter.InitiationDate, adapter.RowNumber));
                            continue;
                        }
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildItemNotInValidFormatInExcelMessage("InitiatedDate", adapter.InitiationDate, adapter.RowNumber));
                        continue;
                    }

                    dbIssue.InitiatedDate = dt;
                }

                //HAZARD
                if (!string.IsNullOrEmpty(adapter.Hazards))
                {
                    if (adapter.Hazards.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.Hazards.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.Hazard = adapter.Hazards.Trim();
                }

                //CONTROL METHOD
                if (!string.IsNullOrEmpty(adapter.ControlMethod))
                {
                    if (adapter.ControlMethod.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.ControlMethod.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.ControlMethod = adapter.ControlMethod.Trim();
                }

                //TRAINING DETAILS
                if (!string.IsNullOrEmpty(adapter.TrainingDetails))
                {
                    if (adapter.TrainingDetails.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error,BuildPropertyTooLong(adapter.TrainingDetails.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.TrainingDetails = adapter.TrainingDetails.Trim();
                }

                //TESTING DETAILS
                if (!string.IsNullOrEmpty(adapter.TestingDetails))
                {
                    if (adapter.TestingDetails.Length > 4000)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildPropertyTooLong(adapter.TestingDetails.Substring(0, 50) + "...", 4000, adapter.RowNumber));
                        continue;
                    }
                    dbIssue.TestingDetails = adapter.TestingDetails.Trim();
                }

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

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

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

                    foreach (string number in areas)
                    {
                        Area areaMatch = (from x in Cee.Areas where x.AreaNumber.ToString() == number.Trim() select x).FirstOrDefault();

                        if (areaMatch != null)
                        {
                            dbIssue.IssueAreas.Add(new IssueArea { Issue = dbIssue, AreaId = areaMatch.Id });
                        }
                        else
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Areas", adapter.AreaNumbers, adapter.RowNumber)));
                            break;
                        }
                    }
                }

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

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

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

                        if (issueCategoryMatch != null)
                        {
                            var issueAssignedCategoryMatch = mExistingIssueAssignedCategories.FirstOrDefault(x => x.IssueId == dbIssue.Id && x.IssueCategoryId == issueCategoryMatch.Id);
                            if (issueAssignedCategoryMatch == null)
                            {
                                var newIssueAssignedCategory = new IssueAssignedCategory {Issue = dbIssue, IssueCategoryId = issueCategoryMatch.Id};
                                dbIssue.IssueAssignedCategories.Add(newIssueAssignedCategory);
                                mExistingIssueAssignedCategories.Add(newIssueAssignedCategory);
                            }

                            var issueApprovalMatch = mExistingIssueApprovals.FirstOrDefault(x => x.IssueId == dbIssue.Id && x.IssueCategoryId == issueCategoryMatch.Id);
                            if (issueApprovalMatch == null)
                            {
                                var newApproval = new IssueApproval {Issue = dbIssue, IssueCategoryId = issueCategoryMatch.Id};
                                dbIssue.IssueApprovals.Add(newApproval);
                                mExistingIssueApprovals.Add(newApproval);
                            }

                            var issueCloseoutMatch = mExistingIssueCloseouts.FirstOrDefault(x => x.IssueId == dbIssue.Id && x.IssueCategoryId == issueCategoryMatch.Id);
                            if (issueCloseoutMatch == null)
                            {
                                var newCloseout = new IssueCloseout { Issue = dbIssue, IssueCategoryId = issueCategoryMatch.Id };
                                dbIssue.IssueCloseouts.Add(newCloseout);
                                mExistingIssueCloseouts.Add(newCloseout);
                            }

                        }
                        else
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("Category", adapterCategoryName, adapter.RowNumber)));
                            break;
                        }
                    }
                }

                //FUNDING
                if (!string.IsNullOrEmpty(adapter.Funding))
                {
                    if (!adapter.Funding.Equals("OPEX", StringComparison.CurrentCultureIgnoreCase) && !adapter.Funding.Equals("CAPEX", StringComparison.CurrentCultureIgnoreCase))
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("Funding Type must be either 'OPEX' or 'CAPEX' - row number {0}.", adapter.RowNumber));
                        continue;
                    }

                    dbIssue.IssueTracking.FundingType = adapter.Funding.ToUpper();
                }

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

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

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

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

                //KEYSTAKEHOLDER
                if (!string.IsNullOrEmpty(adapter.KeyStakeholder))
                {
                    if (adapter.KeyStakeholder.ToUpper() == "NULL")
                    {
                        dbIssue.KeyStakeholder = "";
                    }
                    else
                    {
                        dbIssue.KeyStakeholder = adapter.KeyStakeholder;
                    }
                }

                //ISSUETYPE
                if (!string.IsNullOrEmpty(adapter.IssueType))
                {
                    IssueType issueType = (from x in Cee.IssueTypes where String.Compare(x.Name, adapter.IssueType, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                    if (issueType != null)
                    {
                        dbIssue.IssueTypeId = issueType.Id;
                    }
                    else
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, String.Format(BuildItemNotFoundInDatabaseMessage("IssueType", adapter.IssueType, adapter.RowNumber)));
                        continue;
                    }
                }

                //SUB TYPE
                if (!string.IsNullOrEmpty(adapter.IssueSubType))
                {
                    IssueSubType issueSubType = (from x in mExistingIssueSubTypes where x.Name.Equals(adapter.IssueSubType, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

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

                mSavedResults.Add(dbIssue);
            }

            Cee.SaveChanges();
        }