public ActionResult RiskListAdmin(RiskListParamViewModel vm) { UpdateRiskListParam(vm); return View(vm); }
private void UpdateRiskListParam(RiskListParamViewModel vm) { Dictionary<int, string> posList = new Dictionary<int, string>(); posList.Add(1, "Kantor Pusat"); posList.Add(2, "Cabang"); vm.PosList = new SelectList(posList, "Key", "Value", vm.PosId); Dictionary<int, string> branchList = new Dictionary<int, string>(); foreach (var branch in db.Branches.OrderBy(m => m.ClassId).ThenBy(m => m.BranchName)) branchList.Add(branch.BranchId, branch.BranchName + " (Kelas " + branch.BranchClass.ClassName + ")"); vm.Branches = new SelectList(branchList, "Key", "Value", vm.BranchId); Dictionary<int, string> stateList = new Dictionary<int, string>(); stateList.Add(1, "Belum di-approve"); stateList.Add(2, "Dalam proses approval"); stateList.Add(3, "Approved"); stateList.Add(4, "Tutup"); vm.States = new SelectList(stateList, "Key", "Value", vm.StateId); vm.Risks = db.Risks; if (vm.PosId == 1) vm.Risks = vm.Risks.Where(p => p.DeptId != null); else if (vm.PosId == 2) { vm.Risks = vm.Risks.Where(p => p.BranchId != null); if (vm.BranchId != null) vm.Risks = vm.Risks.Where(p => p.BranchId == vm.BranchId); } switch (vm.StateId) { case 1: vm.Risks = vm.Risks.Where(p => !p.IsReadOnly); break; case 2: vm.Risks = vm.Risks.Where(p => p.IsReadOnly && p.ApprovalDate == null); break; case 3: vm.Risks = vm.Risks.Where(p => p.ApprovalDate != null && p.CloseDate == null); break; case 4: vm.Risks = vm.Risks.Where(p => p.CloseDate != null); break; } vm.Risks = vm.Risks.OrderBy(p => p.RiskDate); }
public ActionResult RiskListAdmin() { RiskListParamViewModel vm = new RiskListParamViewModel(); vm.PosId = 1; vm.StateId = 1; UpdateRiskListParam(vm); return View(vm); }