Beispiel #1
0
        public ActionResult UpdatePartial(int id, string periodeType)
        {
            int pmsSummaryId = id;
            PeriodeType pType = (PeriodeType)Enum.Parse(typeof(PeriodeType), periodeType);

            var request = new GetKpiTargetRequest { PeriodeType = pType, PmsSummaryId = pmsSummaryId };
            var response = _kpiTargetService.GetKpiTarget(request);
            string view = pType == PeriodeType.Yearly ? "_yearly" : "_monthly";
            if (response.IsSuccess)
            {
                var viewModel = response.MapTo<UpdateKpiTargetViewModel>();
                viewModel.PeriodeType = pType.ToString();
                viewModel.PmsSummaryId = pmsSummaryId;
                return PartialView(view, viewModel);
            }

            return Content(response.Message);
        }
Beispiel #2
0
        public GetKpiTargetResponse GetKpiTarget(GetKpiTargetRequest request)
        {
            var response = new GetKpiTargetResponse();
            try
            {
                var pmsSummary = DataContext.PmsSummaries.Single(x => x.Id == request.PmsSummaryId);

                var pillarsAndKpis = DataContext.PmsConfigDetails
                        .Include(x => x.Kpi)
                        .Include(x => x.Kpi.KpiTargets)
                        .Include(x => x.Kpi.Measurement)
                        .Include(x => x.PmsConfig)
                        .Include(x => x.PmsConfig.PmsSummary)
                        .Include(x => x.PmsConfig.Pillar)
                        .Where(x => x.PmsConfig.PmsSummary.Id == request.PmsSummaryId)
                        .ToList()
                        .GroupBy(x => x.PmsConfig.Pillar)
                        .ToDictionary(x => x.Key);

                foreach (var item in pillarsAndKpis)
                {
                    var pillar = new GetKpiTargetResponse.Pillar() { Id = item.Key.Id, Name = item.Key.Name };

                    foreach (var val in item.Value)
                    {
                        var targets = new List<GetKpiTargetResponse.KpiTarget>();
                        switch (request.PeriodeType)
                        {
                            case PeriodeType.Monthly:
                                for (int i = 1; i <= 12; i++)
                                {
                                    var kpiTargetsMonthly = val.Kpi.KpiTargets.FirstOrDefault(x => x.PeriodeType == PeriodeType.Monthly
                                                    && x.Periode.Month == i && x.Periode.Year == pmsSummary.Year);
                                    var kpiTargetMonthly = new GetKpiTargetResponse.KpiTarget();
                                    if (kpiTargetsMonthly == null)
                                    {
                                        kpiTargetMonthly.Id = 0;
                                        kpiTargetMonthly.Periode = new DateTime(pmsSummary.Year, i, 1);
                                        kpiTargetMonthly.Value = null;
                                        kpiTargetMonthly.Remark = null;
                                    }
                                    else
                                    {
                                        kpiTargetMonthly.Id = kpiTargetsMonthly.Id;
                                        kpiTargetMonthly.Periode = kpiTargetsMonthly.Periode;
                                        kpiTargetMonthly.Value = kpiTargetsMonthly.Value;
                                        kpiTargetMonthly.Remark = kpiTargetsMonthly.Remark;
                                    }

                                    targets.Add(kpiTargetMonthly);
                                }
                                break;
                            case PeriodeType.Yearly:
                                var kpiTargetsYearly =
                                    val.Kpi.KpiTargets.FirstOrDefault(x => x.PeriodeType == PeriodeType.Yearly
                                                                           && x.Periode.Year == pmsSummary.Year);
                                var kpiTargetYearly = new GetKpiTargetResponse.KpiTarget();
                                if (kpiTargetsYearly == null)
                                {
                                    kpiTargetYearly.Id = 0;
                                    kpiTargetYearly.Periode = new DateTime(pmsSummary.Year, 1, 1);
                                    kpiTargetYearly.Value = null;
                                    kpiTargetYearly.Remark = null;
                                }
                                else
                                {
                                    kpiTargetYearly.Id = kpiTargetsYearly.Id;
                                    kpiTargetYearly.Periode = kpiTargetsYearly.Periode;
                                    kpiTargetYearly.Value = kpiTargetsYearly.Value;
                                    kpiTargetYearly.Remark = kpiTargetsYearly.Remark;
                                }
                                targets.Add(kpiTargetYearly);

                                break;
                        }

                        var kpi = new GetKpiTargetResponse.Kpi
                            {
                                Id = val.Kpi.Id,
                                Measurement = val.Kpi.Measurement.Name,
                                Name = val.Kpi.Name,
                                KpiTargets = targets
                            };

                        pillar.Kpis.Add(kpi);
                    }

                    response.Pillars.Add(pillar);
                }
                response.IsSuccess = true;
            }
            catch (ArgumentNullException argumentNullException)
            {
                response.Message = argumentNullException.Message;
            }
            catch (InvalidOperationException invalidOperationException)
            {
                response.Message = invalidOperationException.Message;
            }

            return response;
        }
Beispiel #3
0
 public ActionResult Update(int id, string periodeType)
 {
     int pmsSummaryId = id;
     PeriodeType pType = string.IsNullOrEmpty(periodeType)
                     ? PeriodeType.Yearly
                     : (PeriodeType)Enum.Parse(typeof(PeriodeType), periodeType);
     var request = new GetKpiTargetRequest { PeriodeType = pType, PmsSummaryId = pmsSummaryId };
     var response = _kpiTargetService.GetKpiTarget(request);
     if (response.IsSuccess)
     {
         var viewModel = response.MapTo<UpdateKpiTargetViewModel>();
         viewModel.PmsSummaryId = pmsSummaryId;
         viewModel.PeriodeType = pType.ToString();
         viewModel.PeriodeTypes = _dropdownService.GetPeriodeTypesForKpiTargetAndAchievement().MapTo<SelectListItem>();
         return View("Update", viewModel);
     }
     return base.ErrorPage(response.Message);
 }