public ActionResult Create() { var viewModel = new CreateKpiTargetViewModel(); viewModel = SetViewModel(viewModel); return View(viewModel); }
public ActionResult Create(CreateKpiTargetViewModel viewModel) { if (viewModel.PillarKpiTarget.Count > 0) { var request = new CreateKpiTargetsRequest(); request.KpiTargets = new List<CreateKpiTargetsRequest.KpiTarget>(); foreach (var item in viewModel.PillarKpiTarget) { if (item.KpiTargetList.Count > 0) { foreach (var kpi in item.KpiTargetList) { request.KpiTargets.Add(new CreateKpiTargetsRequest.KpiTarget { IsActive = true, KpiId = kpi.KpiId, Periode = kpi.Periode, PeriodeType = (DSLNG.PEAR.Data.Enums.PeriodeType)kpi.PeriodeType, Remark = kpi.Remark, Value = kpi.Value }); } } } var response = _kpiTargetService.Creates(request); TempData["IsSuccess"] = response.IsSuccess; TempData["Message"] = response.Message; if (response.IsSuccess) { return RedirectToAction("Index"); } } viewModel = SetViewModel(viewModel); return View(viewModel); }
public CreateKpiTargetViewModel SetViewModel(CreateKpiTargetViewModel viewModel) { var pmsConfigs = _kpiTargetService.GetPmsConfigs(new GetPmsConfigsRequest { Id = 1 }).PmsConfigs; if (pmsConfigs.Count > 0) { foreach (var pmsConfig in pmsConfigs) { var pillarSelectListItem = new List<SelectListItem>(); pillarSelectListItem.Add(new SelectListItem { Text = pmsConfig.Pillar.Name, Value = pmsConfig.Pillar.Id.ToString() }); var pmsConfigDetails = pmsConfig.PmsConfigDetailsList; if (pmsConfigDetails.Count > 0) { var kpiTargetList = new List<KpiTarget>(); foreach (var pmsConfigDetail in pmsConfigDetails) { var kpiSelectListItem = new List<SelectListItem>(); kpiSelectListItem.Add(new SelectListItem { Text = pmsConfigDetail.Kpi.Name, Value = pmsConfigDetail.Kpi.Id.ToString() }); var kpi = pmsConfigDetail.Kpi.MapTo<Kpi>(); kpiTargetList.Add(new KpiTarget { Kpi = kpi, KpiList = kpiSelectListItem, Periode = new DateTime(pmsConfig.PmsSummary.Year, 1, 1), KpiId = pmsConfigDetail.Kpi.Id //IsActive = pmsConfig.IsActive }); } viewModel.PillarKpiTarget.Add(new PillarTarget { PillarList = pillarSelectListItem, KpiTargetList = kpiTargetList }); } } } return viewModel; }
public ActionResult Create(CreateKpiTargetViewModel viewModel) { if (viewModel.PillarKpiTarget.Count > 0) { var request = new CreateKpiTargetsRequest(); request.KpiTargets = new List<CreateKpiTargetsRequest.KpiTarget>(); foreach (var item in viewModel.PillarKpiTarget) { if (item.KpiTargetList.Count > 0) { foreach (var kpi in item.KpiTargetList) { request.KpiTargets.Add(new CreateKpiTargetsRequest.KpiTarget { IsActive = true, KpiId = kpi.KpiId, Periode = kpi.Periode, PeriodeType = (DSLNG.PEAR.Data.Enums.PeriodeType)kpi.PeriodeType, Remark = kpi.Remark, Value = kpi.Value }); } } } //foreach (var item in viewModel.PillarKpiTarget) //{ // if (item.KpiTargetList.Count > 0) // { // foreach (var kpiTargetList in item.KpiTargetList) // { // if (kpiTargetList.ValueList.Count > 0) // { // for (int i = 0; i < kpiTargetList.ValueList.Count; i++) // { // if (i == 0) // { // kpiTargetList.PeriodeType = DSLNG.PEAR.Data.Enums.PeriodeType.Yearly; // kpiTargetList.Value = kpiTargetList.ValueList[0]; // var kpiTarget = kpiTargetList.MapTo<CreateKpiTargetRequest.KpiTarget>(); // request.KpiTargets.Add(kpiTarget); // } // else // { // kpiTargetList.PeriodeType = DSLNG.PEAR.Data.Enums.PeriodeType.Monthly; // kpiTargetList.Periode = new DateTime(kpiTargetList.Periode.Year, i, 1); // kpiTargetList.Value = kpiTargetList.ValueList[i]; // var kpiTarget = kpiTargetList.MapTo<CreateKpiTargetRequest.KpiTarget>(); // request.KpiTargets.Add(kpiTarget); // } // } // } // } // } //} var response = _kpiTargetService.Creates(request); TempData["IsSuccess"] = response.IsSuccess; TempData["Message"] = response.Message; if (response.IsSuccess) { return RedirectToAction("Index"); } } viewModel = SetViewModel(viewModel); return View(viewModel); }