コード例 #1
0
        public ActionResult ChartMonthly(ViewModels.PmsSummary.ChartViewModel viewModel)
        {
            var artifactDesignerViewModel = new ArtifactDesignerViewModel();
            artifactDesignerViewModel.BarChart = new BarChartViewModel();
            var previewViewModel = new ArtifactPreviewViewModel();
            artifactDesignerViewModel.BarChart.Series.Add(new BarChartViewModel.SeriesViewModel
            {
                KpiId = viewModel.Id,
                Label = "Achievement",
                ValueAxis = ValueAxis.KpiActual.ToString()
            });

            var request = new GetCartesianChartDataRequest();
            request.GraphicName = "Monthly";
            request.GraphicType = "barachievement";
            request.HeaderTitle = "Monthly";
            request.MeasurementId = viewModel.MeasurementId;
            request.PeriodeType = PeriodeType.Monthly;
            request.RangeFilter = RangeFilter.Interval;
            request.Start = new DateTime(viewModel.Year, 1, 1);
            request.End = new DateTime(viewModel.Year, 12, 1);
            request.ValueAxis = ValueAxis.KpiActual;

            artifactDesignerViewModel.BarChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(request);
            var chartData = _artifactService.GetChartData(request);
            previewViewModel.GraphicType = "barachievement";
            previewViewModel.BarChart = new BarChartDataViewModel();
            previewViewModel.BarChart.Title = "Monthly";
            previewViewModel.BarChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
            previewViewModel.BarChart.Series = chartData.Series.MapTo<BarChartDataViewModel.SeriesViewModel>();
            previewViewModel.BarChart.Periodes = chartData.Periodes;
            previewViewModel.BarChart.SeriesType = chartData.SeriesType;
            return Json(previewViewModel, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
ファイル: ArtifactController.cs プロジェクト: cobianwae/Pear
        public ActionResult Preview(ArtifactDesignerViewModel viewModel)
        {
            var previewViewModel = new ArtifactPreviewViewModel();
            previewViewModel.FractionScale = viewModel.FractionScale;
            previewViewModel.MaxFractionScale = viewModel.MaxFractionScale;
            switch (viewModel.GraphicType)
            {
                case "line":
                    {
                        var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                        viewModel.LineChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                        var chartData = _artifactServie.GetChartData(cartesianRequest);
                        var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                        {
                            TimePeriodes = chartData.TimePeriodes,
                            Type = "Overall",
                            PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType)
                        });
                        previewViewModel.PeriodeType = viewModel.PeriodeType;
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.LineChart = new LineChartDataViewModel();
                        previewViewModel.LineChart.Title = viewModel.HeaderTitle;
                        previewViewModel.LineChart.Subtitle = chartData.Subtitle;
                        previewViewModel.LineChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                        previewViewModel.LineChart.Series = chartData.Series.MapTo<LineChartDataViewModel.SeriesViewModel>();
                        previewViewModel.LineChart.Periodes = chartData.Periodes;
                    }
                    break;
                case "area":
                    {
                        var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                        viewModel.AreaChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                        var chartData = _artifactServie.GetChartData(cartesianRequest);
                        var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                        {
                            TimePeriodes = chartData.TimePeriodes,
                            Type = "Overall",
                            PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType)
                        });
                        previewViewModel.PeriodeType = viewModel.PeriodeType;
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.AreaChart = new AreaChartDataViewModel();
                        previewViewModel.AreaChart.Title = viewModel.HeaderTitle;
                        previewViewModel.AreaChart.Subtitle = chartData.Subtitle;
                        previewViewModel.AreaChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                        previewViewModel.AreaChart.Series = chartData.Series.MapTo<AreaChartDataViewModel.SeriesViewModel>();
                        previewViewModel.AreaChart.Periodes = chartData.Periodes;
                        previewViewModel.AreaChart.SeriesType = chartData.SeriesType;
                    }
                    break;
                case "speedometer":
                    {
                        var request = viewModel.MapTo<GetSpeedometerChartDataRequest>();
                        viewModel.SpeedometerChart.MapPropertiesToInstance<GetSpeedometerChartDataRequest>(request);
                        var chartData = _artifactServie.GetSpeedometerChartData(request);
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.SpeedometerChart = new SpeedometerChartDataViewModel();
                        previewViewModel.SpeedometerChart.Title = viewModel.HeaderTitle;
                        previewViewModel.SpeedometerChart.Subtitle = chartData.Subtitle;
                        previewViewModel.SpeedometerChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                        previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                        previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
                    }
                    break;
                case "trafficlight":
                    {
                        var request = viewModel.MapTo<GetTrafficLightChartDataRequest>();
                        viewModel.TrafficLightChart.MapPropertiesToInstance<GetTrafficLightChartDataRequest>(request);
                        var chartData = _artifactServie.GetTrafficLightChartData(request);
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.TrafficLightChart = new TrafficLightChartDataViewModel();
                        previewViewModel.TrafficLightChart.Title = viewModel.HeaderTitle;
                        previewViewModel.TrafficLightChart.Subtitle = chartData.Subtitle;
                        previewViewModel.TrafficLightChart.ValueAxisTitle =
                            _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId })
                                               .Name;
                        previewViewModel.TrafficLightChart.Series =
                            chartData.Series.MapTo<TrafficLightChartDataViewModel.SeriesViewModel>();
                        previewViewModel.TrafficLightChart.PlotBands =
                            chartData.PlotBands.MapTo<TrafficLightChartDataViewModel.PlotBandViewModel>();
                    }
                    break;
                case "tabular":
                    {
                        var request = viewModel.MapTo<GetTabularDataRequest>();
                        /*request.Rows = new List<GetTabularDataRequest.RowRequest>();
                        foreach (var rowViewModel in viewModel.Tabular.Rows)
                        {
                            request.Rows.Add(new GetTabularDataRequest.RowRequest
                                {
                                    End = rowViewModel.EndAfterParsed,
                                    KpiId = rowViewModel.KpiId,
                                    PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), rowViewModel.PeriodeType),
                                    KpiName = rowViewModel.KpiName,
                                    RangeFilter = (RangeFilter)Enum.Parse(typeof(RangeFilter), rowViewModel.RangeFilter),
                                    Start = rowViewModel.StartAfterParsed
                                });
                        }*/

                        viewModel.Tabular.MapPropertiesToInstance<GetTabularDataRequest>(request);

                        var chartData = _artifactServie.GetTabularData(request);
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.Tabular = new TabularDataViewModel();
                        chartData.MapPropertiesToInstance<TabularDataViewModel>(previewViewModel.Tabular);
                        previewViewModel.Tabular.Title = viewModel.HeaderTitle;
                    }
                    break;
                case "tank":
                    {
                        var request = viewModel.MapTo<GetTankDataRequest>();
                        //viewModel.Tank.MapPropertiesToInstance<GetTankDataRequest>(request);
                        var chartData = _artifactServie.GetTankData(request);
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.Tank = new TankDataViewModel();
                        chartData.MapPropertiesToInstance<TankDataViewModel>(previewViewModel.Tank);
                        previewViewModel.Tank.Title = viewModel.HeaderTitle;
                        previewViewModel.Tank.Subtitle = chartData.Subtitle;
                    }
                    break;
                case "multiaxis":
                    {
                        var request = viewModel.MapTo<GetMultiaxisChartDataRequest>();
                        viewModel.MultiaxisChart.MapPropertiesToInstance<GetMultiaxisChartDataRequest>(request);
                        var chartData = _artifactServie.GetMultiaxisChartData(request);
                        var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                        {
                            TimePeriodes = chartData.TimePeriodes,
                            Type = "Overall",
                            PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType)
                        });
                        previewViewModel.PeriodeType = viewModel.PeriodeType;
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.MultiaxisChart = new MultiaxisChartDataViewModel();
                        chartData.MapPropertiesToInstance<MultiaxisChartDataViewModel>(previewViewModel.MultiaxisChart);
                        previewViewModel.MultiaxisChart.Title = viewModel.HeaderTitle;

                    }
                    break;
                case "combo":
                    {
                        var request = viewModel.MapTo<GetComboChartDataRequest>();
                        viewModel.ComboChart.MapPropertiesToInstance<GetComboChartDataRequest>(request);
                        var chartData = _artifactServie.GetComboChartData(request);
                        var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                        {
                            TimePeriodes = chartData.TimePeriodes,
                            Type = "Overall",
                            PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType)
                        });
                        previewViewModel.PeriodeType = viewModel.PeriodeType;
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.ComboChart = new ComboChartDataViewModel();
                        chartData.MapPropertiesToInstance<ComboChartDataViewModel>(previewViewModel.ComboChart);
                        previewViewModel.ComboChart.Title = viewModel.HeaderTitle;

                    }
                    break;
                case "pie":
                    {
                        var request = viewModel.MapTo<GetPieDataRequest>();
                        viewModel.Pie.MapPropertiesToInstance<GetPieDataRequest>(request);
                        var pieData = _artifactServie.GetPieData(request);
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.Pie = pieData.MapTo<PieDataViewModel>();
                        previewViewModel.Pie.Is3D = request.Is3D;
                        previewViewModel.Pie.ShowLegend = request.ShowLegend;
                    }
                    break;

                default:
                    {
                        var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                        viewModel.BarChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                        var chartData = _artifactServie.GetChartData(cartesianRequest);
                        if (!viewModel.AsNetbackChart)
                        {
                            var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                            {
                                TimePeriodes = chartData.TimePeriodes,
                                Type = "Overall",
                                PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType)
                            });
                            previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                        }
                        previewViewModel.AsNetbackChart = viewModel.AsNetbackChart;
                        previewViewModel.PeriodeType = viewModel.PeriodeType;
                        previewViewModel.TimePeriodes = chartData.TimePeriodes;
                        previewViewModel.GraphicType = viewModel.GraphicType;
                        previewViewModel.BarChart = new BarChartDataViewModel();
                        previewViewModel.BarChart.Title = viewModel.HeaderTitle;
                        previewViewModel.BarChart.Subtitle = chartData.Subtitle;
                        previewViewModel.BarChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                        previewViewModel.BarChart.Series = chartData.Series.MapTo<BarChartDataViewModel.SeriesViewModel>();
                        previewViewModel.BarChart.Periodes = chartData.Periodes;
                        previewViewModel.BarChart.SeriesType = chartData.SeriesType;
                    }
                    break;
            }
            return Json(previewViewModel);
        }
コード例 #3
0
ファイル: ArtifactController.cs プロジェクト: cobianwae/Pear
 public ActionResult View(int id)
 {
     var artifactResp = _artifactServie.GetArtifact(new GetArtifactRequest { Id = id });
     var previewViewModel = new ArtifactPreviewViewModel();
     previewViewModel.FractionScale = artifactResp.FractionScale;
     previewViewModel.MaxFractionScale = artifactResp.MaxFractionScale;
     switch (artifactResp.GraphicType)
     {
         case "line":
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest {
                     TimePeriodes = chartData.TimePeriodes,
                     Type = "Overall",
                     PeriodeType = artifactResp.PeriodeType
                 });
                 previewViewModel.PeriodeType = artifactResp.PeriodeType.ToString();
                 previewViewModel.TimePeriodes = chartData.TimePeriodes;
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                 previewViewModel.LineChart = new LineChartDataViewModel();
                 previewViewModel.LineChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.LineChart.Subtitle = chartData.Subtitle;
                 previewViewModel.LineChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.LineChart.Series = chartData.Series.MapTo<LineChartDataViewModel.SeriesViewModel>();
                 previewViewModel.LineChart.Periodes = chartData.Periodes;
             }
             break;
         case "area":
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                 {
                     TimePeriodes = chartData.TimePeriodes,
                     Type = "Overall",
                     PeriodeType = artifactResp.PeriodeType
                 });
                 previewViewModel.PeriodeType = artifactResp.PeriodeType.ToString();
                 previewViewModel.TimePeriodes = chartData.TimePeriodes;
                 previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.AreaChart = new AreaChartDataViewModel();
                 previewViewModel.AreaChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.AreaChart.Subtitle = chartData.Subtitle;
                 previewViewModel.AreaChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.AreaChart.Series = chartData.Series.MapTo<AreaChartDataViewModel.SeriesViewModel>();
                 previewViewModel.AreaChart.Periodes = chartData.Periodes;
             }
             break;
         case "multiaxis":
             {
                 var chartData = _artifactServie.GetMultiaxisChartData(artifactResp.MapTo<GetMultiaxisChartDataRequest>());
                 var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                 {
                     TimePeriodes = chartData.TimePeriodes,
                     Type = "Overall",
                     PeriodeType = artifactResp.PeriodeType
                 });
                 previewViewModel.PeriodeType = artifactResp.PeriodeType.ToString();
                 previewViewModel.TimePeriodes = chartData.TimePeriodes;
                 previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.MultiaxisChart = chartData.MapTo<MultiaxisChartDataViewModel>();
                 previewViewModel.MultiaxisChart.Title = artifactResp.HeaderTitle;
             }
             break;
         case "combo":
             {
                 var chartData = _artifactServie.GetComboChartData(artifactResp.MapTo<GetComboChartDataRequest>());
                 var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                 {
                     TimePeriodes = chartData.TimePeriodes,
                     Type = "Overall",
                     PeriodeType = artifactResp.PeriodeType
                 });
                 previewViewModel.PeriodeType = artifactResp.PeriodeType.ToString();
                 previewViewModel.TimePeriodes = chartData.TimePeriodes;
                 previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.ComboChart = chartData.MapTo<ComboChartDataViewModel>();
                 previewViewModel.ComboChart.Title = artifactResp.HeaderTitle;
             }
             break;
         case "speedometer":
             {
                 var chartData = _artifactServie.GetSpeedometerChartData(artifactResp.MapTo<GetSpeedometerChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.SpeedometerChart = new SpeedometerChartDataViewModel();
                 previewViewModel.SpeedometerChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.SpeedometerChart.Subtitle = chartData.Subtitle;
                 previewViewModel.SpeedometerChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "trafficlight":
             {
                 var chartData = _artifactServie.GetTrafficLightChartData(artifactResp.MapTo<GetTrafficLightChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.TrafficLightChart = new TrafficLightChartDataViewModel();
                 previewViewModel.TrafficLightChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.TrafficLightChart.Subtitle = chartData.Subtitle;
                 previewViewModel.TrafficLightChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.TrafficLightChart.Series = chartData.Series.MapTo<TrafficLightChartDataViewModel.SeriesViewModel>();
                 previewViewModel.TrafficLightChart.PlotBands = chartData.PlotBands.MapTo<TrafficLightChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "tabular":
             {
                 var chartData = _artifactServie.GetTabularData(artifactResp.MapTo<GetTabularDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Tabular = new TabularDataViewModel();
                 chartData.MapPropertiesToInstance<TabularDataViewModel>(previewViewModel.Tabular);
                 previewViewModel.Tabular.Title = artifactResp.HeaderTitle;
                 //previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 //previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "tank":
             {
                 var chartData = _artifactServie.GetTankData(artifactResp.MapTo<GetTankDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Tank = new TankDataViewModel();
                 chartData.MapPropertiesToInstance<TankDataViewModel>(previewViewModel.Tank);
                 previewViewModel.Tank.Title = artifactResp.HeaderTitle;
                 previewViewModel.Tank.Subtitle = chartData.Subtitle;
                 previewViewModel.Tank.Id = artifactResp.Tank.Id;
                 //previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 //previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "pie":
             {
                 var chartData = _artifactServie.GetPieData(artifactResp.MapTo<GetPieDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Pie = chartData.MapTo<PieDataViewModel>();
                 previewViewModel.Pie.Title = artifactResp.HeaderTitle;
                 previewViewModel.Pie.Subtitle = chartData.Subtitle;
                 previewViewModel.Pie.Is3D = artifactResp.Is3D;
                 previewViewModel.Pie.ShowLegend = artifactResp.ShowLegend;
             }
             break;
         default:
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 if (!artifactResp.AsNetbackChart)
                 {
                     var reportHighlights = _highlightService.GetReportHighlights(new GetReportHighlightsRequest
                     {
                         TimePeriodes = chartData.TimePeriodes,
                         Type = "Overall",
                         PeriodeType = artifactResp.PeriodeType
                     });
                     previewViewModel.Highlights = reportHighlights.Highlights.MapTo<ArtifactPreviewViewModel.HighlightViewModel>();
                 }
                 previewViewModel.PeriodeType = artifactResp.PeriodeType.ToString();
                 previewViewModel.TimePeriodes = chartData.TimePeriodes;
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.BarChart = new BarChartDataViewModel();
                 previewViewModel.BarChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.BarChart.Subtitle = chartData.Subtitle;
                 previewViewModel.BarChart.ValueAxisTitle = artifactResp.Measurement; //.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.BarChart.Series = chartData.Series.MapTo<BarChartDataViewModel.SeriesViewModel>();
                 previewViewModel.BarChart.Periodes = chartData.Periodes;
                 previewViewModel.BarChart.SeriesType = chartData.SeriesType;
             }
             break;
     }
     return Json(previewViewModel, JsonRequestBehavior.AllowGet);
 }
コード例 #4
0
ファイル: ArtifactController.cs プロジェクト: irhamkarim/Pear
 public ActionResult View(int id)
 {
     var artifactResp = _artifactServie.GetArtifact(new GetArtifactRequest { Id = id });
     var previewViewModel = new ArtifactPreviewViewModel();
     switch (artifactResp.GraphicType)
     {
         case "line":
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.LineChart = new LineChartDataViewModel();
                 previewViewModel.LineChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.LineChart.Subtitle = chartData.Subtitle;
                 previewViewModel.LineChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.LineChart.Series = chartData.Series.MapTo<LineChartDataViewModel.SeriesViewModel>();
                 previewViewModel.LineChart.Periodes = chartData.Periodes;
             }
             break;
         case "area":
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.AreaChart = new AreaChartDataViewModel();
                 previewViewModel.AreaChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.AreaChart.Subtitle = chartData.Subtitle;
                 previewViewModel.AreaChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.AreaChart.Series = chartData.Series.MapTo<AreaChartDataViewModel.SeriesViewModel>();
                 previewViewModel.AreaChart.Periodes = chartData.Periodes;
             }
             break;
         case "speedometer":
             {
                 var chartData = _artifactServie.GetSpeedometerChartData(artifactResp.MapTo<GetSpeedometerChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.SpeedometerChart = new SpeedometerChartDataViewModel();
                 previewViewModel.SpeedometerChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.SpeedometerChart.Subtitle = chartData.Subtitle;
                 previewViewModel.SpeedometerChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "trafficlight":
             {
                 var chartData = _artifactServie.GetTrafficLightChartData(artifactResp.MapTo<GetTrafficLightChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.TrafficLightChart = new TrafficLightChartDataViewModel();
                 previewViewModel.TrafficLightChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.TrafficLightChart.Subtitle = chartData.Subtitle;
                 previewViewModel.TrafficLightChart.ValueAxisTitle = artifactResp.Measurement;
                 previewViewModel.TrafficLightChart.Series = chartData.Series.MapTo<TrafficLightChartDataViewModel.SeriesViewModel>();
                 previewViewModel.TrafficLightChart.PlotBands = chartData.PlotBands.MapTo<TrafficLightChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "tabular":
             {
                 var chartData = _artifactServie.GetTabularData(artifactResp.MapTo<GetTabularDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Tabular = new TabularDataViewModel();
                 chartData.MapPropertiesToInstance<TabularDataViewModel>(previewViewModel.Tabular);
                 previewViewModel.Tabular.Title = artifactResp.HeaderTitle;
                 //previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 //previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "tank":
             {
                 var chartData = _artifactServie.GetTankData(artifactResp.MapTo<GetTankDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.Tank = new TankDataViewModel();
                 chartData.MapPropertiesToInstance<TankDataViewModel>(previewViewModel.Tank);
                 previewViewModel.Tank.Title = artifactResp.HeaderTitle;
                 previewViewModel.Tank.Subtitle = chartData.Subtitle;
                 //previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 //previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         default:
             {
                 var chartData = _artifactServie.GetChartData(artifactResp.MapTo<GetCartesianChartDataRequest>());
                 previewViewModel.GraphicType = artifactResp.GraphicType;
                 previewViewModel.BarChart = new BarChartDataViewModel();
                 previewViewModel.BarChart.Title = artifactResp.HeaderTitle;
                 previewViewModel.BarChart.Subtitle = chartData.Subtitle;
                 previewViewModel.BarChart.ValueAxisTitle = artifactResp.Measurement; //.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.BarChart.Series = chartData.Series.MapTo<BarChartDataViewModel.SeriesViewModel>();
                 previewViewModel.BarChart.Periodes = chartData.Periodes;
                 previewViewModel.BarChart.SeriesType = chartData.SeriesType;
             }
             break;
     }
     return Json(previewViewModel, JsonRequestBehavior.AllowGet);
 }
コード例 #5
0
ファイル: ArtifactController.cs プロジェクト: irhamkarim/Pear
 public ActionResult Preview(ArtifactDesignerViewModel viewModel)
 {
     var previewViewModel = new ArtifactPreviewViewModel();
     switch (viewModel.GraphicType)
     {
         case "line":
             {
                 var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                 viewModel.LineChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                 var chartData = _artifactServie.GetChartData(cartesianRequest);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.LineChart = new LineChartDataViewModel();
                 previewViewModel.LineChart.Title = viewModel.HeaderTitle;
                 previewViewModel.LineChart.Subtitle = chartData.Subtitle;
                 previewViewModel.LineChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.LineChart.Series = chartData.Series.MapTo<LineChartDataViewModel.SeriesViewModel>();
                 previewViewModel.LineChart.Periodes = chartData.Periodes;
             }
             break;
         case "area":
             {
                 var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                 viewModel.AreaChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                 var chartData = _artifactServie.GetChartData(cartesianRequest);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.AreaChart = new AreaChartDataViewModel();
                 previewViewModel.AreaChart.Title = viewModel.HeaderTitle;
                 previewViewModel.AreaChart.Subtitle = chartData.Subtitle;
                 previewViewModel.AreaChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.AreaChart.Series = chartData.Series.MapTo<AreaChartDataViewModel.SeriesViewModel>();
                 previewViewModel.AreaChart.Periodes = chartData.Periodes;
             }
             break;
         case "speedometer":
             {
                 var request = viewModel.MapTo<GetSpeedometerChartDataRequest>();
                 viewModel.SpeedometerChart.MapPropertiesToInstance<GetSpeedometerChartDataRequest>(request);
                 var chartData = _artifactServie.GetSpeedometerChartData(request);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.SpeedometerChart = new SpeedometerChartDataViewModel();
                 previewViewModel.SpeedometerChart.Title = viewModel.HeaderTitle;
                 previewViewModel.SpeedometerChart.Subtitle = chartData.Subtitle;
                 previewViewModel.SpeedometerChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.SpeedometerChart.Series = chartData.Series.MapTo<SpeedometerChartDataViewModel.SeriesViewModel>();
                 previewViewModel.SpeedometerChart.PlotBands = chartData.PlotBands.MapTo<SpeedometerChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "trafficlight":
             {
                 var request = viewModel.MapTo<GetTrafficLightChartDataRequest>();
                 viewModel.TrafficLightChart.MapPropertiesToInstance<GetTrafficLightChartDataRequest>(request);
                 var chartData = _artifactServie.GetTrafficLightChartData(request);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.TrafficLightChart = new TrafficLightChartDataViewModel();
                 previewViewModel.TrafficLightChart.Title = viewModel.HeaderTitle;
                 previewViewModel.TrafficLightChart.Subtitle = chartData.Subtitle;
                 previewViewModel.TrafficLightChart.ValueAxisTitle =
                     _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId })
                                        .Name;
                 previewViewModel.TrafficLightChart.Series =
                     chartData.Series.MapTo<TrafficLightChartDataViewModel.SeriesViewModel>();
                 previewViewModel.TrafficLightChart.PlotBands =
                     chartData.PlotBands.MapTo<TrafficLightChartDataViewModel.PlotBandViewModel>();
             }
             break;
         case "tabular":
             {
                 var request = viewModel.MapTo<GetTabularDataRequest>();
                 viewModel.Tabular.MapPropertiesToInstance<GetTabularDataRequest>(request);
                 var chartData = _artifactServie.GetTabularData(request);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.Tabular = new TabularDataViewModel();
                 chartData.MapPropertiesToInstance<TabularDataViewModel>(previewViewModel.Tabular);
                 previewViewModel.Tabular.Title = viewModel.HeaderTitle;
             }
             break;
         case "tank":
             {
                 var request = viewModel.MapTo<GetTankDataRequest>();
                 //viewModel.Tank.MapPropertiesToInstance<GetTankDataRequest>(request);
                 var chartData = _artifactServie.GetTankData(request);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.Tank = new TankDataViewModel();
                 chartData.MapPropertiesToInstance<TankDataViewModel>(previewViewModel.Tank);
                 previewViewModel.Tank.Title = viewModel.HeaderTitle;
                 previewViewModel.Tank.Subtitle = chartData.Subtitle;
             }
             break;
         default:
             {
                 var cartesianRequest = viewModel.MapTo<GetCartesianChartDataRequest>();
                 viewModel.BarChart.MapPropertiesToInstance<GetCartesianChartDataRequest>(cartesianRequest);
                 var chartData = _artifactServie.GetChartData(cartesianRequest);
                 previewViewModel.GraphicType = viewModel.GraphicType;
                 previewViewModel.BarChart = new BarChartDataViewModel();
                 previewViewModel.BarChart.Title = viewModel.HeaderTitle;
                 previewViewModel.BarChart.Subtitle = chartData.Subtitle;
                 previewViewModel.BarChart.ValueAxisTitle = _measurementService.GetMeasurement(new GetMeasurementRequest { Id = viewModel.MeasurementId }).Name;
                 previewViewModel.BarChart.Series = chartData.Series.MapTo<BarChartDataViewModel.SeriesViewModel>();
                 previewViewModel.BarChart.Periodes = chartData.Periodes;
                 previewViewModel.BarChart.SeriesType = chartData.SeriesType;
             }
             break;
     }
     return Json(previewViewModel);
 }
コード例 #6
0
ファイル: DerController.cs プロジェクト: fazar/Pear
        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");
        }
コード例 #7
0
ファイル: DerController.cs プロジェクト: cobianwae/Pear
        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 line
                case "line":
                    {

                        var request = new GetCartesianChartDataRequest();
                        request.Start = date.AddDays(-7);
                        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(-7);
                        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.Start = date.AddDays(-7);
                        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.AddDays(-7);
                        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 highlight
                case "highlight":
                    {
                        var highlight =
                            _highlightService.GetHighlightByPeriode(new GetHighlightRequest
                            {
                                Date = date,
                                HighlightTypeId = layout.Highlight.SelectOptionId
                            });
                        var view = RenderPartialViewToString("Display/_Highlight", highlight);
                        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("Display/_Weather", 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("Display/_Alert", 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("Display/_Wave", wave);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region nls
                case "nls":
                    {
                        var vesselSchedule = _vesselScheduleService.GetVesselSchedules(new GetVesselSchedulesRequest
                        {
                            allActiveList = true,
                            Skip = 0,
                            Take = 3,
                        });
                        var schedules = vesselSchedule.VesselSchedules.OrderBy(x => x.ETA).Take(3).ToList();
                        var nls = schedules.MapTo<DailyExecutionReportViewModel.NLSViewModel>();

                        var view = RenderPartialViewToString("Display/_Nls", nls);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region avg ytd key statistic
                case "avg-ytd-key-statistic":
                    {
                        var viewModel = new DisplayAvgYtdKeyStatisticViewModel();

                        for (int i = 1; i <= 6; i++)
                        {
                            var avgYtdKeyStatisticViewModel = new DisplayAvgYtdKeyStatisticViewModel.AvgYtdKeyStatisticViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            avgYtdKeyStatisticViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var actual = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.YTD, YtdFormula.Average);
                                var beforeActual = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date.AddDays(-1), RangeFilter.YTD, YtdFormula.Average);
                                if (actual.Value.HasValue && beforeActual.Value.HasValue)
                                {
                                    if (actual.Value.Value > beforeActual.Value.Value)
                                    {
                                        avgYtdKeyStatisticViewModel.Progress = "up";
                                    }
                                    else if (beforeActual.Value.Value > actual.Value.Value)
                                    {
                                        avgYtdKeyStatisticViewModel.Progress = "down";
                                    }
                                    else
                                    {
                                        avgYtdKeyStatisticViewModel.Progress = "non";
                                    }
                                }
                                else
                                {
                                    avgYtdKeyStatisticViewModel.Progress = "non";
                                }
                                avgYtdKeyStatisticViewModel.KpiName = item.Kpi.Name;
                                avgYtdKeyStatisticViewModel.Ytd = actual.Value.HasValue ? actual.Value.ToString() : "n/a";
                            }

                            viewModel.AvgYtdKeyStatistics.Add(avgYtdKeyStatisticViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_AvgYtdKeyStatistic", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region safety
                case "safety":
                    {
                        var viewModel = new DisplaySafetyTableViewModel();

                        for (int i = 1; i <= 9; i++)
                        {
                            var safetyTableViewModel = new DisplaySafetyTableViewModel.SafetyTableViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            safetyTableViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var currentDay = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.CurrentDay);
                                var mtd = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.MTD);
                                var ytd = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.YTD);
                                var targetYearly = _kpiTargetService.GetKpiTarget(item.Kpi.Id, date, RangeFilter.CurrentYear);
                                var itd = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.AllExistingYears);
                                safetyTableViewModel.KpiName = item.Kpi.Name;
                                safetyTableViewModel.CurrentDay = GetDoubleToString(currentDay.Value);
                                safetyTableViewModel.Mtd = GetDoubleToString(mtd.Value);
                                safetyTableViewModel.Ytd = GetDoubleToString(ytd.Value);
                                safetyTableViewModel.AnnualTarget = GetDoubleToString(targetYearly.Value);
                                safetyTableViewModel.Itd = GetDoubleToString(itd.Value);
                            }

                            viewModel.SafetyTableViewModels.Add(safetyTableViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_SafetyTable", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region security
                case "security":
                    {
                        var viewModel = new DisplaySecurityViewModel();

                        for (int i = 1; i <= 6; i++)
                        {
                            var securityViewModel = new DisplaySecurityViewModel.SecurityViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            securityViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var actual = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, RangeFilter.CurrentDay);
                                securityViewModel.KpiName = item.Kpi.Name;
                                securityViewModel.Value = actual.Value.HasValue ? actual.Value.ToString() : "n/a";
                            }

                            viewModel.SecurityViewModels.Add(securityViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_Security", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region lng and cds
                case "lng-and-cds":
                    {
                        var viewModel = new DisplayLngAndCdsViewModel();
                        for (int i = 0; i < 14; i++)
                        {
                            var procureMentViewModel = new DisplayLngAndCdsViewModel.LngAndCdsViewModel();
                            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.MTD;
                                var mtd = _derService.GetKpiValue(request);
                                procureMentViewModel.Mtd = mtd.Value.HasValue && mtd.Value != null ? mtd.Value.Value.ToString() : "n/a"; ;
                                request.RangeFilter = RangeFilter.YTD;
                                var ytd = _derService.GetKpiValue(request);
                                procureMentViewModel.Ytd = ytd.Value.HasValue && ytd.Value != null ? ytd.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.DisplayLngAndCds.Add(procureMentViewModel);
                        }
                        var view = RenderPartialViewToString("Display/_LngAndCds", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    };
                #endregion
                #region dafwc
                case "dafwc":
                    {
                        var viewModel = new DisplayDafwcViewModel();

                        var response = _derService.GetDafwcData(id, date);
                        viewModel.DaysWithoutDafwc = response.DaysWithoutDafwc;
                        viewModel.DaysWithoutLopc = response.DaysWithoutLopc;
                        viewModel.DaysWithoutDafwcSince = response.DaysWithoutDafwcSince;
                        viewModel.DaysWithoutLopcSince = response.DaysWithoutLopcSince;
                        var view = RenderPartialViewToString("Display/_Dafwc", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region job pmts
                case "job-pmts":
                    {
                        var viewModel = new DisplayJobPmtsViewModel();

                        for (int i = 0; i <= 5; i++)
                        {
                            var jobPmtsViewModel = new DisplayJobPmtsViewModel.JobPmtsViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            jobPmtsViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.KpiId = item.Kpi.Id;
                                request.ConfigType = item.ConfigType;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                jobPmtsViewModel.KpiName = item.Kpi.Name;
                                jobPmtsViewModel.Measurement = item.Kpi.MeasurementName;
                                jobPmtsViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";

                                request.RangeFilter = i < 2 ? RangeFilter.MTD : RangeFilter.CurrentMonth;
                                var mtd = _derService.GetKpiValue(request);
                                jobPmtsViewModel.Mtd = mtd.Value.HasValue ? mtd.Value.Value.ToString() : "n/a";

                                request.RangeFilter = i < 2 ? RangeFilter.YTD : RangeFilter.CurrentYear;
                                var ytd = _derService.GetKpiValue(request);
                                jobPmtsViewModel.Ytd = ytd.Value.HasValue ? ytd.Value.Value.ToString() : "n/a";

                                /*double dailyValue = (daily.Value.HasValue) ? daily.Value.Value : 0;
                                double mtdValue = (mtd.Value.HasValue) ? mtd.Value.Value : 0;
                                double ytdValue = (ytd.Value.HasValue) ? ytd.Value.Value : 0;*/

                            }

                            viewModel.JobPmtsViewModels.Add(jobPmtsViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_JobPmts", 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 = new DisplayTotalFeedGasViewModel();
                        for (int i = 0; i <= 3; i++)
                        {
                            var totalFeedGasViewModel = new DisplayTotalFeedGasViewModel.TotalFeedGasViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                      new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            totalFeedGasViewModel.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);
                                totalFeedGasViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";
                                request.RangeFilter = RangeFilter.MTD;
                                var mtd = _derService.GetKpiValue(request);
                                totalFeedGasViewModel.Mtd = mtd.Value.HasValue ? mtd.Value.Value.ToString() : "n/a";
                                request.RangeFilter = RangeFilter.YTD;
                                var ytd = _derService.GetKpiValue(request);
                                totalFeedGasViewModel.Ytd = ytd.Value.HasValue ? ytd.Value.Value.ToString() : "n/a";
                            }
                            viewModel.TotalFeedGasViewModels.Add(totalFeedGasViewModel);
                        }
                        var view = RenderPartialViewToString("Display/_TotalFeedGas", 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 view = RenderPartialViewToString("Display/_TableTank", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region MGDP
                case "mgdp":
                    {
                        var viewModel = new DisplayMGDPViewModel();

                        for (int i = 0; i <= 5; i++)
                        {
                            var MGDPViewModel = new DisplayMGDPViewModel.MGDPViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            MGDPViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.KpiId = item.Kpi.Id;
                                request.ConfigType = item.ConfigType;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                MGDPViewModel.KpiName = item.Kpi.Name;
                                MGDPViewModel.Measurement = item.Kpi.MeasurementName;
                                MGDPViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.MTD;
                                var mtd = _derService.GetKpiValue(request);
                                MGDPViewModel.Mtd = mtd.Value.HasValue ? mtd.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.YTD;
                                var ytd = _derService.GetKpiValue(request);
                                MGDPViewModel.Ytd = ytd.Value.HasValue ? ytd.Value.Value.ToString() : "n/a";

                                /*double dailyValue = (daily.Value.HasValue) ? daily.Value.Value : 0;
                                double mtdValue = (mtd.Value.HasValue) ? mtd.Value.Value : 0;
                                double ytdValue = (ytd.Value.HasValue) ? ytd.Value.Value : 0;*/

                            }

                            viewModel.MGDPViewModels.Add(MGDPViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_MGDP", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region HHV
                case "hhv":
                    {
                        var viewModel = new DisplayHHVViewModel();
                        for (int i = 0; i <= 3; i++)
                        {
                            var totalHHVViewModel = new DisplayHHVViewModel.HHVViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                      new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            totalHHVViewModel.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);
                                totalHHVViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";
                            }
                            viewModel.HHVViewModels.Add(totalHHVViewModel);
                        }
                        var view = RenderPartialViewToString("Display/_HHV", 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 = new DisplayLngAndCdsProductionViewModel();

                        for (int i = 0; i <= 8; i++)
                        {
                            var MGDPViewModel = new DisplayLngAndCdsProductionViewModel.LngAndCdsProductionViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            MGDPViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.KpiId = item.Kpi.Id;
                                request.ConfigType = item.ConfigType;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                MGDPViewModel.KpiName = item.Kpi.Name;
                                MGDPViewModel.Measurement = item.Kpi.MeasurementName;
                                MGDPViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.MTD;
                                var mtd = _derService.GetKpiValue(request);
                                MGDPViewModel.Mtd = mtd.Value.HasValue ? mtd.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.YTD;
                                var ytd = _derService.GetKpiValue(request);
                                MGDPViewModel.Ytd = ytd.Value.HasValue ? ytd.Value.Value.ToString() : "n/a";

                                /*double dailyValue = (daily.Value.HasValue) ? daily.Value.Value : 0;
                                double mtdValue = (mtd.Value.HasValue) ? mtd.Value.Value : 0;
                                double ytdValue = (ytd.Value.HasValue) ? ytd.Value.Value : 0;*/

                            }

                            viewModel.LngAndCdsProductionViewModels.Add(MGDPViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_LngAndCdsProduction", 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 view = RenderPartialViewToString("Display/_WeeklyMaintenance", 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 view = RenderPartialViewToString("Display/_CriticalPm", 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 view = RenderPartialViewToString("Display/_Procurement", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Indicative Commercial Price
                case "indicative-commercial-price":
                    {
                        var viewModel = new DisplayIndicativeCommercialPriceViewModel();
                        for (int i = 0; i <= 3; i++)
                        {
                            var indicativeCommercialPriceViewModel = new DisplayIndicativeCommercialPriceViewModel.IndicativeCommercialPriceViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                      new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            indicativeCommercialPriceViewModel.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);
                                indicativeCommercialPriceViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";
                            }
                            viewModel.IndicativeCommercialPriceViewModels.Add(indicativeCommercialPriceViewModel);
                        }
                        var view = RenderPartialViewToString("Display/_IndicativeCommercialPrice", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Plant Availability
                case "plant-availability":
                    {
                        var viewModel = new DisplayPlantAvailabilityViewModel();

                        for (int i = 0; i < 10; i++)
                        {
                            var MGDPViewModel = new DisplayPlantAvailabilityViewModel.PlantAvailabilityViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                       new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };

                            MGDPViewModel.Position = item.Position;
                            if (item.Kpi != null)
                            {
                                var request = new GetKpiValueRequest();
                                request.KpiId = item.Kpi.Id;
                                request.ConfigType = item.ConfigType;
                                request.Periode = date;
                                request.RangeFilter = RangeFilter.CurrentDay;
                                var daily = _derService.GetKpiValue(request);
                                MGDPViewModel.KpiName = item.Kpi.Name;
                                MGDPViewModel.Measurement = item.Kpi.MeasurementName;
                                MGDPViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.MTD;
                                var mtd = _derService.GetKpiValue(request);
                                MGDPViewModel.Mtd = mtd.Value.HasValue ? mtd.Value.Value.ToString() : "n/a";

                                request.RangeFilter = RangeFilter.YTD;
                                var ytd = _derService.GetKpiValue(request);
                                MGDPViewModel.Ytd = ytd.Value.HasValue ? ytd.Value.Value.ToString() : "n/a";

                                /*double dailyValue = (daily.Value.HasValue) ? daily.Value.Value : 0;
                                double mtdValue = (mtd.Value.HasValue) ? mtd.Value.Value : 0;
                                double ytdValue = (ytd.Value.HasValue) ? ytd.Value.Value : 0;*/

                            }

                            viewModel.PlantAvailabilityViewModels.Add(MGDPViewModel);
                        }

                        var view = RenderPartialViewToString("Display/_PlantAvalability", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                #endregion
                #region Economic Indicator
                case "economic-indicator":
                    {
                        var viewModel = new DisplayEconomicIndicatorViewModel();
                        for (int i = 0; i <= 10; i++)
                        {
                            var EconomicIndicatorViewModel = new DisplayEconomicIndicatorViewModel.EconomicIndicatorViewModel();
                            var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                                      new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                            EconomicIndicatorViewModel.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);
                                request.Periode = date.AddDays(-1);
                                var yesterday = _derService.GetKpiValue(request);
                                if (daily.Value.HasValue && yesterday.Value.HasValue)
                                {
                                    if (daily.Value.Value > yesterday.Value.Value)
                                    {
                                        EconomicIndicatorViewModel.Progress = "up";
                                    }
                                    else if (yesterday.Value.Value > daily.Value.Value)
                                    {
                                        EconomicIndicatorViewModel.Progress = "down";
                                    }
                                    else
                                    {
                                        EconomicIndicatorViewModel.Progress = "non";
                                    }
                                }
                                else
                                {
                                    EconomicIndicatorViewModel.Progress = "non";
                                }
                                EconomicIndicatorViewModel.Daily = daily.Value.HasValue ? daily.Value.Value.ToString() : "n/a";
                            }
                            viewModel.EconomicIndicatorViewModels.Add(EconomicIndicatorViewModel);
                        }
                        var view = RenderPartialViewToString("Display/_EconomicIndicator", viewModel);
                        var json = new { type = layout.Type.ToLowerInvariant(), view };
                        return Json(json, JsonRequestBehavior.AllowGet);
                    }
                    #endregion

            }
            return Content("Switch case does not matching");
        }