/// <summary>
 /// Create a new RiskImpact object.
 /// </summary>
 /// <param name="riskId">Initial value of the RiskId property.</param>
 /// <param name="isMoneyImpact">Initial value of the IsMoneyImpact property.</param>
 public static RiskImpact CreateRiskImpact(global::System.Int32 riskId, global::System.Boolean isMoneyImpact)
 {
     RiskImpact riskImpact = new RiskImpact();
     riskImpact.RiskId = riskId;
     riskImpact.IsMoneyImpact = isMoneyImpact;
     return riskImpact;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the RiskImpacts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRiskImpacts(RiskImpact riskImpact)
 {
     base.AddObject("RiskImpacts", riskImpact);
 }
Exemple #3
0
        public ActionResult ImpactMoneyEdit(RiskImpact impact, int id)
        {
            if (ModelState.IsValid)
            {
                UserData data = Utils.LoadUserDataFromSession();
                using (TransactionScope trans = new TransactionScope())
                {
                    try
                    {
                        decimal moneyValue = 0M;
                        if (impact.MoneyDirect != null)
                            moneyValue += (decimal)impact.MoneyDirect;
                        if (impact.MoneyIndirect != null)
                            moneyValue += (decimal)impact.MoneyIndirect;

                        var impactPos = Utils.GetImpactPos(data);
                        var level = Utils.GetImpactLevelFromMoney(moneyValue, impactPos);

                        impact.ImpactLevelId = level;

                        db.RiskImpacts.Attach(impact);
                        db.ObjectStateManager.ChangeObjectState(impact, EntityState.Modified);
                        db.SaveChanges();

                        var risk = db.Risks.Single(p => p.RiskId == id);
                        risk.ImpactMoney = moneyValue;
                        risk.ImpactLevelId = level;
                        Utils.CalcRiskLevel(risk);
                        db.SaveChanges();
                        trans.Complete();
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", "Tidak bisa menyimpan data. Error: " + e.Message);
                        return View(impact);
                    }

                    return RedirectToAction("ImpactDetail", new { id = id });
                }

            }
            return View(impact);
        }
Exemple #4
0
        public ActionResult ImpactEdit(RiskImpact impact, int id)
        {
            if (ModelState.IsValid)
            {
                RiskImpact oldImpact = db.RiskImpacts.Where(p => p.RiskId == id).FirstOrDefault();
                if (oldImpact.IsMoneyImpact != impact.IsMoneyImpact)
                {
                    using (TransactionScope trans = new TransactionScope())
                    {
                        try
                        {
                            oldImpact.IsMoneyImpact = impact.IsMoneyImpact;
                            oldImpact.MoneyDirect = null;
                            oldImpact.MoneyIndirect = null;
                            oldImpact.ImpactLevelId = Utils.IMPACTLEVEL1;

                            if (impact.IsMoneyImpact)
                            {
                                var nonMoneys = db.RiskNonMoneyImpacts.Where(p => p.RiskId == id).ToList();
                                foreach (var item in nonMoneys)
                                    db.RiskNonMoneyImpacts.DeleteObject(item);
                            }

                            Risk risk = db.Risks.Where(p => p.RiskId == id).FirstOrDefault();
                            risk.ImpactLevelId = Utils.IMPACTLEVEL1;
                            risk.ImpactMoney = null;
                            Utils.CalcRiskLevel(risk);

                            db.SaveChanges();
                            trans.Complete();
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", "Tidak bisa menyimpan data. Error: " + e.Message);
                            return View(impact);
                        }
                    }
                }

                if (impact.IsMoneyImpact)
                    return RedirectToAction("ImpactMoneyEdit", new { id = id });
                else
                    return RedirectToAction("ImpactNonMoneyList", new { id = id });
            }
            return View(impact);
        }
Exemple #5
0
        public ActionResult ImpactDetail(int id)
        {
            RiskImpact impact = db.RiskImpacts.Where(p=>p.RiskId==id).FirstOrDefault();
            if (impact == null)
            {
                impact = new RiskImpact();
                impact.RiskId = id;
                impact.IsMoneyImpact = true;
                impact.ImpactLevelId = Utils.IMPACTLEVEL1;
                db.RiskImpacts.AddObject(impact);
                db.SaveChanges();

                impact.Risk.ImpactLevelId = Utils.IMPACTLEVEL1;
                if (impact.Risk.ProbLevelId != null)
                    impact.Risk.RiskLevel = (int)impact.Risk.ProbLevelId * (int)impact.Risk.ImpactLevelId;
                db.SaveChanges();
            }
            RiskImpactModelView vm = new RiskImpactModelView();
            vm.RiskImpact = impact;
            vm.RiskNonMoneyImpacts = db.RiskNonMoneyImpacts.Where(p => p.RiskId == id);
            return View(vm);
        }
Exemple #6
0
        public ActionResult RiskNew(RiskEditViewModel vm)
        {
            UserData data = Utils.LoadUserDataFromSession();
            bool saved = true;
            if (ModelState.IsValid)
            {
                if (vm.Risk.CauseGroupId != null && vm.Risk.CauseId == null)
                {
                    ModelState.AddModelError("", "Sebab Risiko harus diisi lengkap atau kosong sama sekali");
                    saved = false;
                }
                if (vm.Risk.EffectGroupId != null && vm.Risk.EffectId == null)
                {
                    ModelState.AddModelError("", "Akibat Risiko harus diisi lengkap atau kosong sama sekali");
                    saved = false;
                }
                if (vm.Risk.RiskCatId != null && vm.Risk.RiskTypeId == null)
                {
                    ModelState.AddModelError("", "Klasifikasi Risiko harus diisi lengkap atau kosong sama sekali");
                    saved = false;
                }

                if (saved)
                {
                    try
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            Risk risk = new Risk();
                            risk.UserId = data.UserId;
                            risk.JobTitle = data.JobTitle;
                            risk.RiskCode = Utils.GetFormattedSerialNumber(data);
                            risk.RiskName = vm.Risk.RiskName;
                            risk.RiskDate = vm.Risk.RiskDate;
                            risk.OrgPos = data.OrgPos;
                            risk.DeptId = data.DeptId;
                            risk.SubDeptId = data.SubDeptId;
                            risk.DivisionId = data.DivisionId;
                            risk.SubDivId = data.SubDivId;
                            risk.BranchId = data.BranchId;
                            risk.SubBranchId = data.SubBranchId;
                            risk.BizUnitId = data.BizUnitId;
                            if (vm.Risk.CauseId != null)
                            {
                                risk.CauseGroupId = vm.Risk.CauseGroupId;
                                risk.CauseTypeId = vm.Risk.CauseTypeId;
                                risk.CauseId = vm.Risk.CauseId;
                            }
                            if (vm.Risk.EffectId != null)
                            {
                                risk.EffectGroupId = vm.Risk.EffectGroupId;
                                risk.EffectTypeId = vm.Risk.EffectTypeId;
                                risk.EffectId = vm.Risk.EffectId;
                            }
                            if (vm.Risk.RiskTypeId != null)
                            {
                                risk.RiskCatId = vm.Risk.RiskCatId;
                                risk.RiskGroupId = vm.Risk.RiskGroupId;
                                risk.RiskTypeId = vm.Risk.RiskTypeId;
                            }
                            risk.ProbLevelId = Utils.PROBLEVEL1;
                            risk.ImpactLevelId = Utils.IMPACTLEVEL1;
                            risk.RiskLevel = risk.ProbLevelId * risk.ImpactLevelId;
                            risk.IsReadOnly = false;
                            db.Risks.AddObject(risk);
                            db.SaveChanges();

                            RiskProb prob = new RiskProb();
                            prob.RiskId = risk.RiskId;
                            prob.ProbOption = Utils.PROBOPTION_FREQUENCY;
                            prob.FreqId = Utils.FREQUENCY1;
                            prob.ProbLevelId = Utils.PROBLEVEL1;
                            db.RiskProbs.AddObject(prob);
                            db.SaveChanges();

                            RiskImpact impact = new RiskImpact();
                            impact.RiskId = risk.RiskId;
                            impact.IsMoneyImpact = true;
                            impact.ImpactLevelId = Utils.IMPACTLEVEL1;
                            db.RiskImpacts.AddObject(impact);
                            db.SaveChanges();

                            Utils.CreateFirstApprovalSchedule(risk.RiskId);
                            Utils.IncrementSerialNumber(db);

                            trans.Complete();
                            return RedirectToAction("RiskDetail", new { id = risk.RiskId });
                        }
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", "Tidak bisa menyimpan data risiko. Error: " + e.Message);
                    }
                }
            }

            vm.Risk.RiskCode = Utils.GetFormattedSerialNumber(data);

            vm.CauseGroups = new SelectList(db.CauseGroups, "CauseGroupId", "CauseGroupName");
            vm.CauseTypes = new SelectList(db.CauseTypes.Where(p => p.CauseGroupId == vm.Risk.CauseGroupId), "CauseTypeId", "CauseTypeName");
            vm.Causes = new SelectList(db.Causes.Where(p => p.CauseTypeId == vm.Risk.CauseTypeId), "CauseId", "CauseName");

            vm.EffectGroups = new SelectList(db.EffectGroups, "EffectGroupId", "EffectGroupName");
            vm.EffectTypes = new SelectList(db.EffectTypes.Where(p => p.EffectGroupId == vm.Risk.EffectGroupId), "EffectTypeId", "EffectTypeName");
            vm.Effects = new SelectList(db.Effects.Where(p => p.EffectTypeId == vm.Risk.EffectTypeId), "EffectId", "EffectName");

            vm.RiskCats = new SelectList(db.RiskCats, "RiskCatId", "RiskCatName");
            vm.RiskGroups = new SelectList(db.RiskGroups.Where(p => p.RiskCatId == vm.Risk.RiskCatId), "RiskGroupId", "RiskGroupName");
            vm.RiskTypes = new SelectList(db.RiskTypes.Where(p => p.RiskGroupId == vm.Risk.RiskGroupId), "RiskTypeId", "RiskTypeName");

            return View(vm);
        }