Esempio n. 1
0
 public CreateKpiTargetsResponse Creates(CreateKpiTargetsRequest request)
 {
     var response = new CreateKpiTargetsResponse();
     try
     {
         if (request.KpiTargets.Count > 0)
         {
             foreach (var kpiTarget in request.KpiTargets)
             {
                 var data = kpiTarget.MapTo<KpiTarget>();
                 data.Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == kpiTarget.KpiId);
                 DataContext.KpiTargets.Add(data);
                 DataContext.SaveChanges();
             }
             response.IsSuccess = true;
             response.Message = "KPI Target has been added successfully";
         }
     }
     catch (DbUpdateException dbUpdateException)
     {
         response.Message = dbUpdateException.Message;
     }
     return response;
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }