예제 #1
0
 /// <summary>
 /// Create a new MitigationApproval object.
 /// </summary>
 /// <param name="approvalId">Initial value of the ApprovalId property.</param>
 /// <param name="mitigationId">Initial value of the MitigationId property.</param>
 /// <param name="orgPos">Initial value of the OrgPos property.</param>
 /// <param name="lastApproval">Initial value of the LastApproval property.</param>
 /// <param name="isReadOnly">Initial value of the IsReadOnly property.</param>
 public static MitigationApproval CreateMitigationApproval(global::System.Int32 approvalId, global::System.Int32 mitigationId, global::System.Int32 orgPos, global::System.Boolean lastApproval, global::System.Boolean isReadOnly)
 {
     MitigationApproval mitigationApproval = new MitigationApproval();
     mitigationApproval.ApprovalId = approvalId;
     mitigationApproval.MitigationId = mitigationId;
     mitigationApproval.OrgPos = orgPos;
     mitigationApproval.LastApproval = lastApproval;
     mitigationApproval.IsReadOnly = isReadOnly;
     return mitigationApproval;
 }
예제 #2
0
파일: Utils.cs 프로젝트: ryanask/MRK
 public static void CreateFirstMitigationApprovalSchedule(int mitigationId, AskrindoMVCEntities db)
 {
     var mg = db.RiskMitigations.Single(p => p.MitigationId == mitigationId);
     MitigationApproval apr = new MitigationApproval();
     apr.MitigationId = mitigationId;
     apr.OrgPos = mg.OrgPos;
     switch (apr.OrgPos)
     {
         case ORGPOS_DEPT:
             apr.DeptId = mg.DeptId;
             break;
         case ORGPOS_SUBDEPT:
             apr.SubDeptId = mg.SubDeptId;
             break;
         case ORGPOS_DIVISION:
             apr.DivisionId = mg.DivisionId;
             break;
         case ORGPOS_SUBDIV:
             apr.SubDivId = mg.SubDivId;
             break;
         case ORGPOS_BRANCH:
             apr.BranchId = mg.BranchId;
             break;
         case ORGPOS_SUBBRANCH:
             apr.SubBranchId = mg.SubBranchId;
             break;
         case ORGPOS_BIZUNIT:
             apr.BizUnitId = mg.BizUnitId;
             break;
     }
     apr.LastApproval = apr.OrgPos == ORGPOS_SUBDEPT || apr.OrgPos == ORGPOS_DIVISION || apr.OrgPos == ORGPOS_BRANCH;
     apr.IsReadOnly = false;
     db.MitigationApprovals.AddObject(apr);
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the MitigationApprovals EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMitigationApprovals(MitigationApproval mitigationApproval)
 {
     base.AddObject("MitigationApprovals", mitigationApproval);
 }
예제 #4
0
파일: Utils.cs 프로젝트: ryanask/MRK
        //public static void ApproveMitigation(int mitigationId, AskrindoMVCEntities db)
        //{
        //    UserData data = Utils.LoadUserDataFromSession();
        //    RiskMitigation mitigation = db.RiskMitigations.Where(p => p.MitigationId == mitigationId).FirstOrDefault();
        //    using (TransactionScope trans = new TransactionScope())
        //    {
        //        mitigation.ApprovalDate = DateTime.Now;
        //        mitigation.UserId = data.UserId;
        //        mitigation.JobTitle = data.JobTitle;
        //        RiskState rs = new RiskState();
        //        rs.RiskId = mitigation.RiskId;
        //        rs.MitigationId = mitigation.MitigationId;
        //        rs.StateDate = (DateTime)mitigation.ApprovalDate;
        //        rs.ProbLevelId = (int)mitigation.ProbLevelId;
        //        rs.ImpactLevelId = (int)mitigation.ImpactLevelId;
        //        rs.RiskLevel = (int)mitigation.RiskLevel;
        //        db.RiskStates.AddObject(rs);
        //        db.SaveChanges();
        //        trans.Complete();
        //    }
        //}
        //public static void CancelMitigationApproval(int mitigationId, AskrindoMVCEntities db)
        //{
        //    UserData data = Utils.LoadUserDataFromSession();
        //    RiskMitigation mitigation = db.RiskMitigations.Where(p => p.MitigationId == mitigationId).FirstOrDefault();
        //    using (TransactionScope trans = new TransactionScope())
        //    {
        //        mitigation.ApprovalDate = null;
        //        mitigation.UserId = null;
        //        mitigation.JobTitle = null;
        //        RiskState rs = db.RiskStates.Where(p => p.RiskId == mitigation.RiskId && p.MitigationId == mitigation.MitigationId).FirstOrDefault();
        //        if (rs != null)
        //            db.RiskStates.DeleteObject(rs);
        //        db.SaveChanges();
        //        trans.Complete();
        //    }
        //}
        public static void ApproveMitigation(int approvalId, AskrindoMVCEntities db)
        {
            using (TransactionScope trans = new TransactionScope())
            {
                UserData data = LoadUserDataFromSession();
                MitigationApproval apr = db.MitigationApprovals.Where(p => p.ApprovalId == approvalId).FirstOrDefault();
                apr.ApprovalDate = DateTime.Now;
                apr.UserId = data.UserId;
                apr.JobTitle = data.JobTitle;
                db.SaveChanges();

                apr.RiskMitigation.IsReadOnly = true;
                db.SaveChanges();

                if (apr.LastApproval)
                {
                    // mitigation approval complete
                    apr.RiskMitigation.ApprovalDate = apr.ApprovalDate;
                    db.SaveChanges();

                    MitigationApproval prevApr = db.MitigationApprovals
                        .Where(p => p.MitigationId == apr.MitigationId && p.ApprovalId != apr.ApprovalId && p.ApprovalDate != null)
                        .FirstOrDefault();
                    if (prevApr != null)
                        prevApr.IsReadOnly = true;
                    db.SaveChanges();

                    RiskState rs = new RiskState();
                    rs.RiskId = apr.RiskMitigation.RiskId;
                    rs.MitigationId = apr.MitigationId;
                    rs.StateDate = (DateTime)apr.ApprovalDate;
                    rs.ProbLevelId = (int)apr.RiskMitigation.ProbLevelId;
                    rs.ImpactLevelId = (int)apr.RiskMitigation.ImpactLevelId;
                    rs.RiskLevel = (int)apr.RiskMitigation.RiskLevel;
                    db.RiskStates.AddObject(rs);
                    db.SaveChanges();
                }
                else
                {
                    // create next approval schedule
                    MitigationApproval nextApr = new MitigationApproval();
                    nextApr.MitigationId = apr.MitigationId;
                    nextApr.LimitDate = DateTime.Now.AddDays(Utils.MAX_LIMIT_APPROVAL_DAYS);
                    nextApr.LastApproval = true;

                    switch (apr.OrgPos)
                    {
                        case Utils.ORGPOS_SUBDIV:
                            SubDiv subDiv = db.SubDivs.Single(p => p.SubDivId == apr.SubDivId);
                            nextApr.OrgPos = Utils.ORGPOS_DIVISION;
                            nextApr.DivisionId = subDiv.DivisionId;
                            break;
                        case Utils.ORGPOS_SUBBRANCH:
                            SubBranch subBranch = db.SubBranches.Single(p => p.SubBranchId == apr.SubBranchId);
                            nextApr.OrgPos = Utils.ORGPOS_BRANCH;
                            nextApr.BranchId = subBranch.BranchId;
                            break;
                        case Utils.ORGPOS_BIZUNIT:
                            BizUnit bizUnit = db.BizUnits.Single(p => p.BizUnitId == apr.BizUnitId);
                            nextApr.OrgPos = Utils.ORGPOS_BRANCH;
                            nextApr.BranchId = bizUnit.BranchId;
                            break;
                    }
                    db.MitigationApprovals.AddObject(nextApr);
                    db.SaveChanges();
                }
                trans.Complete();
            }
        }