Example #1
0
 /// <summary>
 /// Create a new RiskState object.
 /// </summary>
 /// <param name="stateId">Initial value of the StateId property.</param>
 /// <param name="riskId">Initial value of the RiskId property.</param>
 /// <param name="stateDate">Initial value of the StateDate property.</param>
 /// <param name="probLevelId">Initial value of the ProbLevelId property.</param>
 /// <param name="impactLevelId">Initial value of the ImpactLevelId property.</param>
 /// <param name="riskLevel">Initial value of the RiskLevel property.</param>
 public static RiskState CreateRiskState(global::System.Int32 stateId, global::System.Int32 riskId, global::System.DateTime stateDate, global::System.Int32 probLevelId, global::System.Int32 impactLevelId, global::System.Int32 riskLevel)
 {
     RiskState riskState = new RiskState();
     riskState.StateId = stateId;
     riskState.RiskId = riskId;
     riskState.StateDate = stateDate;
     riskState.ProbLevelId = probLevelId;
     riskState.ImpactLevelId = impactLevelId;
     riskState.RiskLevel = riskLevel;
     return riskState;
 }
Example #2
0
File: Utils.cs Project: 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();
            }
        }
Example #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the RiskStates EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRiskStates(RiskState riskState)
 {
     base.AddObject("RiskStates", riskState);
 }
Example #4
0
        public ActionResult ApproveRiskConfirmed(int id)
        {
            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    UserData data = Utils.LoadUserDataFromSession();
                    RiskApproval apr = db.RiskApprovals.Where(p => p.ApprovalId == id).FirstOrDefault();
                    apr.ApprovalDate = DateTime.Now;
                    apr.UserId = data.UserId;
                    apr.JobTitle = data.JobTitle;
                    db.SaveChanges();

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

                    if (apr.LastApproval)
                    {
                        // risk approval completed
                        apr.Risk.ApprovalDate = apr.ApprovalDate;
                        db.SaveChanges();

                        RiskApproval prevApr = db.RiskApprovals
                            .Where(p => p.RiskId == apr.RiskId && p.ApprovalId != apr.ApprovalId && p.ApprovalDate != null)
                            .FirstOrDefault();
                        if (prevApr != null)
                        {
                            prevApr.IsReadOnly = true;
                            db.SaveChanges();
                        }

                        RiskState rs = new RiskState();
                        rs.RiskId = apr.RiskId;
                        rs.StateDate = (DateTime)apr.ApprovalDate;
                        rs.ProbLevelId = (int)apr.Risk.ProbLevelId;
                        rs.ImpactLevelId = (int)apr.Risk.ImpactLevelId;
                        rs.RiskLevel = (int)apr.Risk.RiskLevel;
                        db.RiskStates.AddObject(rs);
                        db.SaveChanges();
                    }
                    else
                    {
                        // next approval schedule
                        RiskApproval nextApr = new RiskApproval();
                        nextApr.RiskId = apr.RiskId;
                        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;
                                nextApr.OrgName = subDiv.Division.DivisionName;
                                break;
                            case Utils.ORGPOS_SUBBRANCH:
                                SubBranch subBranch = db.SubBranches.Single(p => p.SubBranchId == apr.SubBranchId);
                                nextApr.OrgPos = Utils.ORGPOS_BRANCH;
                                nextApr.BranchId = subBranch.BranchId;
                                nextApr.OrgName = subBranch.Branch.BranchName;
                                break;
                            case Utils.ORGPOS_BIZUNIT:
                                BizUnit biz = db.BizUnits.Single(p => p.BizUnitId == apr.BizUnitId);
                                nextApr.OrgPos = Utils.ORGPOS_BRANCH;
                                nextApr.BranchId = biz.BranchId;
                                nextApr.OrgName = biz.Branch.BranchName;
                                break;
                        }
                        db.RiskApprovals.AddObject(nextApr);
                        db.SaveChanges();
                    }
                    trans.Complete();
                }
                catch (Exception e)
                {
                    ViewBag.Message = "Tidak bisa meng-approve data peristiwa risiko : " + e.Message;
                    return View("Error");
                }
            }
            return RedirectToAction("ApproveRiskSuccess");
        }