Exemple #1
0
        private DisplayKpiInformationViewModel GetGeneralDerKpiInformations(int numberOfKpi, GetDerLayoutitemResponse layout, DateTime date, PeriodeType periodeType)
        {
            var viewModel = new DisplayKpiInformationViewModel();

            for (int i = 0; i < numberOfKpi; i++)
            {
                var kpiInformationVm = new DisplayKpiInformationViewModel.KpiInformationViewModel { Position = i };
                var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                           new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                if (item.Kpi != null)
                {
                    kpiInformationVm = item.MapTo<DisplayKpiInformationViewModel.KpiInformationViewModel>();
                    //var achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, periodeType);
                    //kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                    if (item.ConfigType.Equals(ConfigType.KpiAchievement))
                    {
                        var achievement = new Services.Responses.KpiAchievement.GetKpiAchievementResponse();
                        if (item.Kpi.Id == 62)
                        {
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, new DateTime(date.Year, date.Month, 1), PeriodeType.Monthly);
                        }
                        else if (item.Kpi.Id == 385)
                        {
                            var prevMonth = date.AddMonths(-1);
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, new DateTime(prevMonth.Year, prevMonth.Month, 1), PeriodeType.Monthly);
                        }
                        else
                        {
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, periodeType);
                        }
                        kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                    }
                    else if (item.ConfigType.Equals(ConfigType.KpiTarget))
                    {
                        var target = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue { Kpi_Id = item.Kpi.Id, periode = date, PeriodeType = periodeType.ToString() });
                        kpiInformationVm.DerItemValue = target.MapTo<DerItemValueViewModel>();
                    }
                }

                viewModel.KpiInformationViewModels.Add(kpiInformationVm);
            }

            return viewModel;
        }
Exemple #2
0
        public ActionResult LayoutItem(int id, string currentDate)
        {
            DateTime date;
            bool isDate = DateTime.TryParse(currentDate, out date);
            var layout = _derService.GetDerLayoutItem(id);
            switch (layout.Type.ToLowerInvariant())
            {
                #region avg ytd key statistic
                case "avg-ytd-key-statistic":
                    {
                        var view = RenderPartialViewToString("~/Views/Der/Display/_AvgYtdKeyStatistic.cshtml", GetGeneralDerKpiInformations(5, layout, date, PeriodeType.Daily));
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region flare
                case "flare":
                    {
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Flare.cshtml", GetGeneralDerKpiInformations(9, layout, date, PeriodeType.Daily));
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region temperature
                case "temperature":
                    {
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Temperature.cshtml", GetGeneralDerKpiInformations(2, layout, date, PeriodeType.Daily));
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region line
                case "line":
                    {

                        var request = new GetCartesianChartDataRequest();
                        request.Start = date.AddDays(-6);
                        request.End = date;
                        request.HeaderTitle = layout.Artifact.HeaderTitle;
                        request.MeasurementId = layout.Artifact.MeasurementId;
                        request.PeriodeType = PeriodeType.Daily;
                        request.RangeFilter = RangeFilter.Interval;
                        request.ValueAxis = ValueAxis.KpiActual;

                        var series = layout.Artifact.Series.Select(x => new GetCartesianChartDataRequest.SeriesRequest
                        {
                            Color = x.Color,
                            KpiId = x.KpiId,
                            Label = x.Label
                        }).ToList();
                        request.Series = series;
                        var chartData = _artifactService.GetChartData(request);

                        var previewViewModel = new ArtifactPreviewViewModel();
                        previewViewModel.PeriodeType = "Daily";
                        previewViewModel.Highlights = new List<ArtifactPreviewViewModel.HighlightViewModel>();
                        for (DateTime counter = request.Start.Value;
                             counter <= request.End.Value;
                             counter = counter.AddDays(1))
                        {
                            previewViewModel.Highlights.Add(null);
                        }
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.GraphicType = layout.Type;
                        previewViewModel.LineChart = new LineChartDataViewModel();
                        previewViewModel.LineChart.Title = layout.Artifact.HeaderTitle;
                        previewViewModel.LineChart.Subtitle = chartData.Subtitle;
                        previewViewModel.LineChart.ValueAxisTitle = layout.Artifact.MeasurementName;
                        previewViewModel.LineChart.Series =
                            chartData.Series.MapTo<LineChartDataViewModel.SeriesViewModel>();
                        previewViewModel.LineChart.Periodes = chartData.Periodes;
                        return Json(previewViewModel, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region multiaxis
                case "multiaxis":
                    {
                        var request = new GetMultiaxisChartDataRequest();
                        request.PeriodeType = PeriodeType.Daily;
                        request.RangeFilter = RangeFilter.Interval;
                        request.Start = date.AddDays(-6);
                        request.End = date;

                        var previewViewModel = new ArtifactPreviewViewModel();

                        request.Charts = layout.Artifact.Charts.MapTo<GetMultiaxisChartDataRequest.ChartRequest>();
                        var chartData = _artifactService.GetMultiaxisChartData(request);
                        previewViewModel.PeriodeType = "Daily";
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.Highlights = new List<ArtifactPreviewViewModel.HighlightViewModel>();
                        for (DateTime counter = request.Start.Value;
                             counter <= request.End.Value;
                             counter = counter.AddDays(1))
                        {
                            previewViewModel.Highlights.Add(null);
                        }
                        previewViewModel.GraphicType = layout.Type;
                        previewViewModel.MultiaxisChart = new MultiaxisChartDataViewModel();
                        chartData.MapPropertiesToInstance<MultiaxisChartDataViewModel>(previewViewModel.MultiaxisChart);
                        previewViewModel.MultiaxisChart.Title = layout.Artifact.HeaderTitle;
                        return Json(previewViewModel, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region pie
                case "pie":
                    {
                        var request = new GetPieDataRequest();
                        request.PeriodeType = PeriodeType.Daily;
                        request.RangeFilter = RangeFilter.Interval;
                        request.ValueInformation = ArtifactValueInformation.Mtd;
                        request.Start = date;
                        request.End = date;
                        request.HeaderTitle = layout.Artifact.HeaderTitle;

                        request.ValueAxis = ValueAxis.KpiActual;

                        var series = layout.Artifact.Series.Select(x => new GetPieDataRequest.SeriesRequest
                        {
                            Color = x.Color,
                            KpiId = x.KpiId,
                            Label = x.Label
                        }).ToList();
                        request.Series = series;
                        var chartData = _artifactService.GetPieData(request);

                        var previewViewModel = new ArtifactPreviewViewModel();
                        previewViewModel.PeriodeType = "Daily";
                        previewViewModel.Highlights = new List<ArtifactPreviewViewModel.HighlightViewModel>();
                        for (DateTime counter = request.Start.Value;
                             counter <= request.End.Value;
                             counter = counter.AddDays(1))
                        {
                            previewViewModel.Highlights.Add(null);
                        }

                        previewViewModel.GraphicType = layout.Type;
                        previewViewModel.Pie = chartData.MapTo<PieDataViewModel>();
                        previewViewModel.Pie.Is3D = layout.Artifact.Is3D;
                        previewViewModel.Pie.ShowLegend = layout.Artifact.ShowLegend;
                        previewViewModel.Pie.Title = layout.Artifact.HeaderTitle;
                        previewViewModel.Pie.Subtitle = chartData.Subtitle;
                        previewViewModel.Pie.SeriesResponses =
                            chartData.SeriesResponses.MapTo<PieDataViewModel.SeriesResponse>();

                        return Json(previewViewModel, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region tank
                case "tank":
                    {
                        var request = new GetTankDataRequest();
                        request.PeriodeType = PeriodeType.Daily;
                        request.RangeFilter = RangeFilter.Interval;
                        request.Start = date;
                        request.End = date;
                        request.Tank = layout.Artifact.Tank.MapTo<GetTankDataRequest.TankRequest>();
                        var previewViewModel = new ArtifactPreviewViewModel();
                        var chartData = _artifactService.GetTankData(request);
                        previewViewModel.GraphicType = layout.Artifact.GraphicType;
                        previewViewModel.Tank = new TankDataViewModel();
                        chartData.MapPropertiesToInstance<TankDataViewModel>(previewViewModel.Tank);
                        previewViewModel.Tank.Title = layout.Artifact.HeaderTitle;
                        previewViewModel.Tank.Subtitle = chartData.Subtitle;
                        previewViewModel.Tank.Id = layout.Artifact.Tank.Id;
                        return Json(previewViewModel, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region speedometer
                case "barmeter":
                case "speedometer":
                    {
                        var request = new GetSpeedometerChartDataRequest();
                        request.Start = date;
                        request.End = date;
                        request.PeriodeType = PeriodeType.Daily;
                        request.RangeFilter = RangeFilter.Interval;
                        request.ValueAxis = ValueAxis.KpiActual;
                        request.PlotBands = layout.Artifact.Plots.Select(x => new GetSpeedometerChartDataRequest.PlotBandRequest
                        {
                            From = x.From,
                            Color = x.Color,
                            To = x.To
                        }).ToList();
                        request.Series = new GetSpeedometerChartDataRequest.SeriesRequest
                        {
                            KpiId = layout.Artifact.CustomSerie.Id,
                            Label = layout.Artifact.CustomSerie.Name
                        };
                        if (layout.Artifact.Series.Count > 0) {
                            request.LabelSeries = new GetSpeedometerChartDataRequest.SeriesRequest
                            {
                                KpiId = layout.Artifact.Series[0].KpiId,
                                Label = layout.Artifact.Series[0].Label
                            };
                        }

                        var chartData = _artifactService.GetSpeedometerChartData(request);

                        var previewViewModel = new ArtifactPreviewViewModel();
                        previewViewModel.PeriodeType = "Daily";
                        previewViewModel.Highlights = new List<ArtifactPreviewViewModel.HighlightViewModel>();
                        for (DateTime counter = request.Start.Value;
                             counter <= request.End.Value;
                             counter = counter.AddDays(1))
                        {
                            previewViewModel.Highlights.Add(null);
                        }
                        previewViewModel.GraphicType = layout.Type;
                        previewViewModel.SpeedometerChart = new SpeedometerChartDataViewModel();
                        previewViewModel.SpeedometerChart.Title = layout.Artifact.HeaderTitle;
                        previewViewModel.SpeedometerChart.Subtitle = chartData.Subtitle;
                        previewViewModel.SpeedometerChart.ValueAxisTitle = layout.Artifact.MeasurementName;
                        previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                        if (layout.Artifact.Series.Count > 0)
                        {
                            previewViewModel.SpeedometerChart.LabelSeries = new SpeedometerChartDataViewModel.LabelSeriesViewModel
                            {
                                name = chartData.LabelSeries.name,
                                value = chartData.LabelSeries.data
                            };
                        }

                        previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
                        previewViewModel.SpeedometerChart.PlotBands = previewViewModel.SpeedometerChart.PlotBands.OrderBy(x => x.to).ToList();
                        return Json(previewViewModel, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region highlight
                case "highlight":
                    {
                        var highlight =
                            _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                            {
                                Date = date,
                                HighlightTypeId = layout.Highlight.SelectOptionId
                            });
                        JToken obj;
                        string view;
                        if (!Helpers.HtmlHelpers.IsValidJson(highlight.Message, out obj))
                        {
                            view = RenderPartialViewToString("~/Views/Der/Display/_Highlight.cshtml", highlight);
                        }
                        else
                        {
                            view = highlight.Message.Replace(System.Environment.NewLine, "");
                        }

                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region weather
                case "weather":
                    {
                        var weather = _weatherService.GetWeather(new GetWeatherRequest
                        {
                            Date = date,
                            ByDate = true
                        });

                        var view = RenderPartialViewToString("~/Views/Der/Display/_Weather.cshtml", weather);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region alert
                case "alert":
                    {
                        var alert = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                        {
                            Type = "Alert",
                            Date = date
                        });
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Alert.cshtml", alert);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region wave
                case "wave":
                    {
                        var wave = _waveService.GetWave(new GetWaveRequest
                        {
                            Date = date,
                            ByDate = true
                        });
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Wave.cshtml", wave);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Next Loading Schedule
                case "nls":
                    {
                        var vesselSchedule = _derLoadingScheduleService.Get(new GetDerLoadingSchedulesRequest { Periode = date, StrictDate = true });
                        var schedules = vesselSchedule.VesselSchedules;
                        var nls = schedules.MapTo<DailyExecutionReportViewModel.NLSViewModel>();

                        var view = RenderPartialViewToString("~/Views/Der/Display/_Nls.cshtml", nls);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region safety
                case "safety":
                    {
                        var viewModel = GetGeneralDerKpiInformations(11, layout, date, PeriodeType.Daily);
                        var target0 = layout.KpiInformations.SingleOrDefault(x => x.Position == 0);
                        var target1 = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        var target2 = layout.KpiInformations.SingleOrDefault(x => x.Position == 2);
                        var target3 = layout.KpiInformations.SingleOrDefault(x => x.Position == 3);
                        var target4 = layout.KpiInformations.SingleOrDefault(x => x.Position == 4);
                        var target5 = layout.KpiInformations.SingleOrDefault(x => x.Position == 5);
                        var target6 = layout.KpiInformations.SingleOrDefault(x => x.Position == 6);
                        var target7 = layout.KpiInformations.SingleOrDefault(x => x.Position == 7);
                        var target8 = layout.KpiInformations.SingleOrDefault(x => x.Position == 8);
                        var target9 = layout.KpiInformations.SingleOrDefault(x => x.Position == 9);
                        var target10 = layout.KpiInformations.SingleOrDefault(x => x.Position == 10);
                        viewModel.KpiInformationViewModels.Add(AddTarget(11, target0, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(12, target1, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(13, target2, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(14, target3, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(15, target4, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(16, target5, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(17, target6, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(18, target7, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(19, target8, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(20, target9, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(21, target10, date));

                        var view = RenderPartialViewToString("~/Views/Der/Display/_SafetyTable.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region security
                case "security":
                    {
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Security.cshtml", GetGeneralDerKpiInformations(6, layout, date, PeriodeType.Daily));
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region lng and cds
                case "lng-and-cds":
                    {

                        var viewModel = GetGeneralDerKpiInformations(17, layout, date, PeriodeType.Daily);
                        var target4 = layout.KpiInformations.SingleOrDefault(x => x.Position == 4);
                        var target5 = layout.KpiInformations.SingleOrDefault(x => x.Position == 5);
                        var target6 = layout.KpiInformations.SingleOrDefault(x => x.Position == 6);
                        var target7 = layout.KpiInformations.SingleOrDefault(x => x.Position == 7);
                        var target8 = layout.KpiInformations.SingleOrDefault(x => x.Position == 8);
                        var target9 = layout.KpiInformations.SingleOrDefault(x => x.Position == 9);
                        viewModel.KpiInformationViewModels.Add(AddTarget(17, target4, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(18, target5, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(19, target6, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(20, target7, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(21, target8, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(22, target9, date));
                        viewModel.DateInfo = date;
                        var view = RenderPartialViewToString("~/Views/Der/Display/_LngAndCds.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    };
                #endregion
                #region dafwc
                case "dafwc":
                    {
                        var viewModel = new DisplayKpiInformationViewModel();

                        for (int i = 0; i < 3; i++)
                        {
                            var kpiInformationVm = new DisplayKpiInformationViewModel.KpiInformationViewModel { Position = i };
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            if (item.Kpi != null)
                            {
                                kpiInformationVm = item.MapTo<DisplayKpiInformationViewModel.KpiInformationViewModel>();
                                if (item.ConfigType.Equals(ConfigType.KpiAchievement))
                                {
                                    var achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, PeriodeType.Daily);
                                    kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                                }
                                else if (item.ConfigType.Equals(ConfigType.KpiTarget))
                                {
                                    var achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, PeriodeType.Daily);
                                    kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                                }
                            }

                            viewModel.KpiInformationViewModels.Add(kpiInformationVm);
                        }
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Dafwc.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region job pmts
                case "job-pmts":
                    {

                        var viewModel = GetGeneralDerKpiInformations(3, layout, date, PeriodeType.Daily);
                        var target1 = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        viewModel.KpiInformationViewModels.Add(AddTarget(3, target1, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_JobPmts.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region total feed gas
                case "total-feed-gas":
                    {
                        var viewModel = GetGeneralDerKpiInformations(3, layout, date, PeriodeType.Daily);
                        var view = RenderPartialViewToString("~/Views/Der/Display/_TotalFeedGas.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region table tank
                case "table-tank":
                    {
                        /*var viewModel = new DisplayTableTankViewModel();
                        for (int i = 0; i <= 10; i++)
                        {
                            var totalTableTankViewModel = new DisplayTableTankViewModel.TableTankViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                      new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            totalTableTankViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.ConfigType = item.ConfigType;
                                request.KpiId = item.Kpi.Id;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                totalTableTankViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";
                            }
                            viewModel.TableTankViewModels.Add(totalTableTankViewModel);
                        }*/
                        var viewModel = GetGeneralDerKpiInformations(15, layout, date, PeriodeType.Daily);
                        var view = RenderPartialViewToString("~/Views/Der/Display/_TableTank.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region MGDP
                case "mgdp":
                    {
                        var viewModel = GetGeneralDerKpiInformations(3, layout, date, PeriodeType.Daily);// new DisplayKpiInformationViewModel();
                        var target = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        viewModel.KpiInformationViewModels.Add(AddTarget(3, target, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_MGDP.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region HHV
                case "hhv":
                    {
                        var viewModel = GetGeneralDerKpiInformations(2, layout, date, PeriodeType.Daily);
                        var target0 = layout.KpiInformations.SingleOrDefault(x => x.Position == 0);
                        var target1 = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        viewModel.KpiInformationViewModels.Add(AddTarget(2, target0, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(3, target1, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_HHV.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region LNG and CDS Production
                case "lng-and-cds-production":
                    {

                        var viewModel = GetGeneralDerKpiInformations(10, layout, date, PeriodeType.Daily);
                        viewModel.DateInfo = date;
                        var target7 = layout.KpiInformations.SingleOrDefault(x => x.Position == 7);
                        var target8 = layout.KpiInformations.SingleOrDefault(x => x.Position == 8);
                        viewModel.KpiInformationViewModels.Add(AddTarget(10, target7, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(11, target8, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_LngAndCdsProduction.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region weekly maintenance
                case "weekly-maintenance":
                    {
                        /*var viewModel = new DisplayWeeklyMaintenanceViewModel();
                        DateTime lastWednesday = date;
                        while (lastWednesday.DayOfWeek != DayOfWeek.Wednesday)
                            lastWednesday = lastWednesday.AddDays(-1);
                        viewModel.Date = lastWednesday.ToString("dd MMM yyyy");
                        for (int i = 0; i <= 3; i++)
                        {
                            var weeklyMaintenanceViewModel = new DisplayWeeklyMaintenanceViewModel.WeeklyMaintenanceViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            weeklyMaintenanceViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.ConfigType = item.ConfigType;
                                request.KpiId = item.Kpi.Id;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentWeek;
                                var weekly = _derService.GetKpiValue(request);
                                weeklyMaintenanceViewModel.Weekly = weekly.Value.HasValue && weekly.Value != null ? weekly.Value.Value.ToString() : "n/a"; ;
                            }
                            else if (item.SelectOption != null)
                            {
                                var highlight = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                                {
                                    Date = date,
                                    HighlightTypeId = item.SelectOption.Id
                                });
                                weeklyMaintenanceViewModel.Remarks = !string.IsNullOrEmpty(highlight.Message)
                                                                         ? highlight.Message
                                                                         : "n/a";
                            }
                            viewModel.WeeklyMaintenanceViewModels.Add(weeklyMaintenanceViewModel);
                        }*/

                        var viewModel = GetGeneralDerKpiInformations(3, layout, date, PeriodeType.Daily);
                        var target2 = layout.KpiInformations.SingleOrDefault(x => x.Position == 2);
                        viewModel.KpiInformationViewModels.Add(AddTarget(3, target2, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_WeeklyMaintenance.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region critical PM
                case "critical-pm":
                    {
                        /*var viewModel = new DisplayCriticalPmViewModel();
                        for (int i = 0; i <= 4; i++)
                        {
                            var criticalViewModel = new DisplayCriticalPmViewModel.CriticalPmViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            criticalViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.ConfigType = item.ConfigType;
                                request.KpiId = item.Kpi.Id;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentWeek;
                                var weekly = _derService.GetKpiValue(request);
                                criticalViewModel.Weekly = weekly.Value.HasValue && weekly.Value != null ? weekly.Value.Value.ToString() : "n/a"; ;
                            }
                            else if (item.SelectOption != null)
                            {
                                var highlight = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                                {
                                    Date = date,
                                    HighlightTypeId = item.SelectOption.Id
                                });
                                criticalViewModel.Remarks = !string.IsNullOrEmpty(highlight.Message)
                                                                         ? highlight.Message
                                                                         : "n/a";
                            }
                            viewModel.CriticalPmViewModels.Add(criticalViewModel);
                        }*/

                        var viewModel = GetGeneralDerKpiInformations(4, layout, date, PeriodeType.Daily);
                        var target1 = layout.KpiInformations.SingleOrDefault(x => x.Position == 3);
                        viewModel.KpiInformationViewModels.Add(AddTarget(4, target1, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_CriticalPm.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region procurement
                case "procurement":
                    {
                        /*var viewModel = new DisplayProcurementViewModel();
                        for (int i = 0; i <= 3; i++)
                        {
                            var procureMentViewModel = new DisplayProcurementViewModel.ProcurementViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            procureMentViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.ConfigType = item.ConfigType;
                                request.KpiId = item.Kpi.Id;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                procureMentViewModel.Daily = daily.Value.HasValue && daily.Value != null ? daily.Value.Value.ToString() : "n/a"; ;
                            }
                            else if (item.SelectOption != null)
                            {
                                var highlight = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                                {
                                    Date = date,
                                    HighlightTypeId = item.SelectOption.Id
                                });
                                procureMentViewModel.Remarks = !string.IsNullOrEmpty(highlight.Message)
                                                                         ? highlight.Message
                                                                         : "n/a";
                            }
                            viewModel.ProcurementViewModels.Add(procureMentViewModel);
                        }*/

                        var viewModel = GetGeneralDerKpiInformations(2, layout, date, PeriodeType.Daily);
                        var target2 = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        viewModel.KpiInformationViewModels.Add(AddTarget(2, target2, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_Procurement.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Indicative Commercial Price
                case "indicative-commercial-price":
                    {
                        var monthlyDate = new DateTime(date.Year, date.Month, 1);
                        var viewModel = GetGeneralDerKpiInformations(4, layout, monthlyDate, PeriodeType.Monthly);
                        var view = RenderPartialViewToString("~/Views/Der/Display/_IndicativeCommercialPrice.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Plant Availability
                case "plant-availability":
                    {
                        var viewModel = GetGeneralDerKpiInformations(11, layout, date, PeriodeType.Daily);
                        viewModel.DateInfo = date;
                        var target0 = layout.KpiInformations.SingleOrDefault(x => x.Position == 0);
                        var target1 = layout.KpiInformations.SingleOrDefault(x => x.Position == 1);
                        var target2 = layout.KpiInformations.SingleOrDefault(x => x.Position == 2);
                        var target3 = layout.KpiInformations.SingleOrDefault(x => x.Position == 3);
                        viewModel.KpiInformationViewModels.Add(AddTarget(11, target0, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(12, target1, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(13, target2, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(14, target3, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_PlantAvalability.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Economic Indicator
                case "economic-indicator":
                    {
                        var viewModel = GetGeneralDerKpiInformations(15, layout, date, PeriodeType.Daily);
                        viewModel.DateInfo = date;
                        //var jccPrice = layout.KpiInformations.Where(x => x.Position == 3).FirstOrDefault();
                        //if(jccPrice != null)
                        //{
                        //    var monhtlyDate = new DateTime(date.Year, date.Month, 1);
                        //    var monthly = _kpiAchievementService.GetKpiAchievement(jccPrice.Kpi.Id, monhtlyDate, PeriodeType.Monthly);
                        //    if(monthly.Value.HasValue)
                        //    {
                        //        viewModel.KpiInformationViewModels.First(x => x.Position == 3).DerItemValue.Value = monthly.Value.Value.ToString();
                        //    }
                        //}

                        TempData["month"] = date.ToString("MMM", CultureInfo.InvariantCulture);
                        var view = RenderPartialViewToString("~/Views/Der/Display/_EconomicIndicator.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Key Equipment Status
                case "key-equipment-status":
                    {
                        var viewModel = new DisplayKeyEquipmentStatusViewModel();
                        for (int i = 0; i <= 23; i++)
                        {
                            var keyEquipmentViewModel = new DisplayKeyEquipmentStatusViewModel.KeyEquipmentStatusViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            keyEquipmentViewModel.Position = item.Position;
                            string message = "N/A";
                            if (item.SelectOption != null)
                            {
                                var request = new GetHighlightRequest();
                                request.Date = date;
                                request.HighlightTypeId = item.SelectOption.Id;

                                var highlight = _highlightService.GetHighlightByPeriode(request);
                                if (!string.IsNullOrEmpty(highlight.Message)) message = highlight.Message;
                            }

                            keyEquipmentViewModel.highlight = message;
                            viewModel.KeyEquipmentStatusViewModels.Add(keyEquipmentViewModel);
                        }
                        var view = RenderPartialViewToString("~/Views/Der/Display/_KeyEquipmentStatus.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Global Stock Market
                case "global-stock-market":
                    {
                        var viewModel = GetGeneralDerKpiInformations(13, layout, date, PeriodeType.Daily);
                        int highlightId = 0;
                        if (layout.KpiInformations.SingleOrDefault(x => x.Position == 8) != null && layout.KpiInformations.Single(x => x.Position == 8).SelectOption != null)
                        {
                            highlightId = layout.KpiInformations.Single(x => x.Position == 8).SelectOption.Id;
                        }
                        var highlight =
                            _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                            {
                                Date = date,
                                HighlightTypeId = highlightId
                            });
                        viewModel.KpiInformationViewModels.Single(x => x.Position == 8).DerItemValue.Value =
                            highlight.Message;
                        var view = RenderPartialViewToString("~/Views/Der/Display/_GlobalStockMarket.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Loading Duration
                case "loading-duration":
                    {
                        var viewModel = GetGeneralDerKpiInformations(4, layout, date, PeriodeType.Daily);
                        var target0 = layout.KpiInformations.SingleOrDefault(x => x.Position == 0);
                        var target2 = layout.KpiInformations.SingleOrDefault(x => x.Position == 2);
                        viewModel.KpiInformationViewModels.Add(AddTarget(4, target0, date));
                        viewModel.KpiInformationViewModels.Add(AddTarget(5, target2, date));
                        var view = RenderPartialViewToString("~/Views/Der/Display/_LoadingDuration.cshtml", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Termometer
                case "termometer":
                    {
                        var viewModel = GetGeneralDerKpiInformations(1, layout, date, PeriodeType.Daily);
                        return Json(new { GraphicType = "termometer", Value = viewModel.KpiInformationViewModels[0].DerItemValue.Value }, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Person On Board
                case "person-on-board":
                    {
                        var viewModel = GetGeneralDerKpiInformations(1, layout, date, PeriodeType.Daily);
                        var view = RenderPartialViewToString("~/Views/Der/Display/_PersonOnBoard.cshtml", viewModel);
                        return Json(new { type = layout.Type.ToLowerInvariant(), view = view }, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Prepared By
                case "prepared-by":
                    {
                        var viewModel = new DisplaySignedByViewModel();
                        var user = _userService.GetUser(new Services.Requests.User.GetUserRequest { Id = layout.SignedBy });
                        viewModel.FullName = user.FullName;
                        viewModel.SignatureImage = user.SignatureImage;
                        viewModel.Time = "LT07:45";
                        viewModel.Position = user.Position;
                        var view = RenderPartialViewToString("~/Views/Der/Display/_PreparedBy.cshtml", viewModel);
                        return Json(new { type = layout.Type.ToLowerInvariant(), view = view }, JsonRequestBehavior.AllowGet);
                    }
                case "reviewed-by":
                    {
                        var viewModel = new DisplaySignedByViewModel();
                        var user = _userService.GetUser(new Services.Requests.User.GetUserRequest { Id = layout.SignedBy });
                        viewModel.FullName = user.FullName;
                        viewModel.SignatureImage = user.SignatureImage;
                        viewModel.Position = user.Position;
                        var view = RenderPartialViewToString("~/Views/Der/Display/_ReviewedBy.cshtml", viewModel);
                        return Json(new { type = layout.Type.ToLowerInvariant(), view = view }, JsonRequestBehavior.AllowGet);
                    }
                    #endregion
            }
            return Content("Switch case does not matching");
        }
Exemple #3
0
        private DisplayKpiInformationViewModel.KpiInformationViewModel AddTarget(int position, GetDerLayoutitemResponse.KpiInformationResponse target, DateTime date)
        {
            var kpiInformationVm = new DisplayKpiInformationViewModel.KpiInformationViewModel { Position = position };

            if (target != null)
            {
                kpiInformationVm.DerItemValue = new DerItemValueViewModel();
                var daily = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = date,
                    PeriodeType = PeriodeType.Daily.ToString()
                });
                var mtd = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = new DateTime(date.Year, date.Month, 1),
                    PeriodeType = PeriodeType.Monthly.ToString()
                });

                var ytd = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = new DateTime(date.Year, 1, 1),
                    PeriodeType = PeriodeType.Yearly.ToString()
                });
                kpiInformationVm.DerItemValue.Value = daily.Value.ToString(); ;
                kpiInformationVm.DerItemValue.Mtd = mtd.Value.ToString(); ;
                kpiInformationVm.DerItemValue.Ytd = ytd.Value.ToString(); ;
                var obj = new
                {
                    daily = daily.Remark,
                    mtd = mtd.Remark,
                    ytd = ytd.Remark
                };
                var json = new JavaScriptSerializer().Serialize(obj);
                kpiInformationVm.DerItemValue.Remark = json;

            }

            return kpiInformationVm;
        }