Exemple #1
0
        public ActionResult ImpactNonMoneySelect(ImpactSelectViewModel vm, int id)
        {
            if (vm.ImpactTypeId != 0 && vm.ImpactLeveliId != 0)
            {
                ImpactDetail detail = db.ImpactDetails.
                    Where(p => p.ImpactTypeId == vm.ImpactTypeId &&
                               p.ImpactLevelId == vm.ImpactLeveliId).FirstOrDefault();
                RiskNonMoneyImpact nmImpact = db.RiskNonMoneyImpacts.
                    Where(p => p.RiskId == id &&
                               p.ImpactTypeId == vm.ImpactTypeId).FirstOrDefault();
                if (nmImpact == null)
                {
                    nmImpact = new RiskNonMoneyImpact();
                    nmImpact.RiskId = id;
                    nmImpact.ImpactDetailId = detail.ImpactDetailId;
                    nmImpact.ImpactTypeId = vm.ImpactTypeId;
                    nmImpact.ImpactLevelId = vm.ImpactLeveliId;
                    db.RiskNonMoneyImpacts.AddObject(nmImpact);
                }
                else
                {
                    nmImpact.ImpactDetailId = detail.ImpactDetailId;
                    nmImpact.ImpactLevelId = vm.ImpactLeveliId;
                }
                db.SaveChanges();

                var maxLevelId = db.RiskNonMoneyImpacts.Where(p => p.RiskId == id).Max(p => p.ImpactLevelId);
                var risk = db.Risks.Where(p => p.RiskId == id).FirstOrDefault();
                risk.ImpactLevelId = maxLevelId;
                Utils.CalcRiskLevel(risk);
                db.SaveChanges();
                return RedirectToAction("ImpactNonMoneyList", new { id = id });
            }
            if (vm.ImpactTypeId == 0)
                ModelState.AddModelError("", "Dampak harus diisi");
            if (vm.ImpactLeveliId == 0)
                ModelState.AddModelError("", "Tingkat Dampak harus diisi");
            vm.Risk = db.Risks.Where(p => p.RiskId == id).FirstOrDefault();
            vm.ImpactCats = db.ImpactCats;
            vm.ImpactLevels = db.ImpactLevels;
            vm.ImpactDetails = db.ImpactDetails.Where(p => p.ImpactTypeId == vm.ImpactTypeId);
            return View(vm);
        }
Exemple #2
0
 public ActionResult ImpactNonMoneySelect(int id)
 {
     ImpactSelectViewModel vm = new ImpactSelectViewModel();
     vm.RiskId = id;
     vm.Risk = db.Risks.Where(p => p.RiskId == id).FirstOrDefault();
     vm.ImpactCats = db.ImpactCats;
     vm.ImpactLevels = db.ImpactLevels;
     vm.ImpactDetails = db.ImpactDetails.Where(p => p.ImpactTypeId == vm.ImpactTypeId);
     return View(vm);
 }