Exemplo n.º 1
0
        public ActionResult LayoutItem(DerLayoutItemViewModel viewModel)
        {
            if (viewModel.Id > 0)
            {
                #region edit
                var response      = _derService.GetDerLayoutItem(viewModel.Id);
                var editViewModel = response.MapTo <DerLayoutItemViewModel>();
                editViewModel.Types = _dropdownService.GetDerItemTypes().OrderBy(x => x.Text).MapTo <SelectListItem>();
                editViewModel.Type  = response.Type;
                switch (response.Type.ToLowerInvariant())
                {
                case "line":
                {
                    var lineChart = new LineChartViewModel();
                    editViewModel.LineChart = response.Artifact.MapPropertiesToInstance <LineChartViewModel>(lineChart);
                    var series = new LineChartViewModel.SeriesViewModel();
                    editViewModel.LineChart.Series.Insert(0, series);
                    editViewModel.Artifact.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                          .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    break;
                }

                case "pie":
                {
                    var pie = new PieViewModel();
                    editViewModel.Pie = response.Artifact.MapPropertiesToInstance <PieViewModel>(pie);
                    var series = new PieViewModel.SeriesViewModel();
                    editViewModel.Pie.Series.Insert(0, series);
                    editViewModel.Artifact.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                          .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    break;
                }

                case "tank":
                {
                    var tank = new TankViewModel();
                    editViewModel.Tank = response.Artifact.Tank.MapPropertiesToInstance <TankViewModel>(tank);
                    break;
                }

                case "multiaxis":
                {
                    var multiaxisChart = new MultiaxisChartViewModel();
                    editViewModel.MultiaxisChart = response.Artifact.MapPropertiesToInstance <MultiaxisChartViewModel>(multiaxisChart);
                    multiaxisChart.GraphicTypes.Add(new SelectListItem {
                            Value = "line", Text = "Line"
                        });
                    multiaxisChart.ValueAxes.Add(new SelectListItem {
                            Value = ValueAxis.KpiActual.ToString(), Text = "Kpi Actual"
                        });
                    multiaxisChart.Measurements = _measurementService.GetMeasurements(new GetMeasurementsRequest
                        {
                            Take = -1,
                            SortingDictionary = new Dictionary <string, SortOrder> {
                                { "Name", SortOrder.Ascending }
                            }
                        }).Measurements
                                                  .Select(x => new SelectListItem {
                            Value = x.Id.ToString(), Text = x.Name
                        }).ToList();
                    foreach (var chartRes in response.Artifact.Charts)
                    {
                        var chartViewModel = chartRes.MapTo <MultiaxisChartViewModel.ChartViewModel>();
                        switch (chartViewModel.GraphicType)
                        {
                        case "line":
                        {
                            chartViewModel.LineChart = chartRes.MapTo <LineChartViewModel>();
                            chartViewModel.LineChart.ValueAxes.Add(new SelectListItem {
                                        Value = ValueAxis.KpiActual.ToString(), Text = "Kpi Actual"
                                    });
                            var series = new LineChartViewModel.SeriesViewModel();
                            chartViewModel.LineChart.Series.Insert(0, series);
                        }
                        break;
                        }
                        multiaxisChart.Charts.Add(chartViewModel);
                    }
                    var chart = new MultiaxisChartViewModel.ChartViewModel();
                    editViewModel.MultiaxisChart.Charts.Insert(0, chart);

                    break;
                }

                case "speedometer":
                case "barmeter":
                {
                    var speedometerChart = new SpeedometerChartViewModel();
                    editViewModel.SpeedometerChart = response.Artifact.MapPropertiesToInstance <SpeedometerChartViewModel>(speedometerChart);
                    var plot = new SpeedometerChartViewModel.PlotBand();
                    editViewModel.SpeedometerChart.PlotBands.Insert(0, plot);
                    break;
                }

                case "highlight":
                {
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    editViewModel.HighlightId = response.Highlight.SelectOptionId;
                    break;
                }

                case "key-equipment-status":
                {
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 24);
                    for (int i = 0; i < response.KpiInformations.Count; i++)
                    {
                        if (response.KpiInformations[i].SelectOption != null)
                        {
                            editViewModel.KpiInformations[i].HighlightId = response.KpiInformations[i].SelectOption.Id;
                        }
                    }
                }
                break;

                case "termometer":
                case "person-on-board":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 1);
                    break;
                }

                case "hhv":
                case "procurement":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 2);
                    break;
                }

                case "mgdp":
                case "indicative-commercial-price":
                case "dafwc":
                case "job-pmts":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 3);
                    break;
                }

                case "total-feed-gas":
                case "weekly-maintenance":
                case "critical-pm":
                case "loading-duration":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 4);
                    break;
                }

                case "avg-ytd-key-statistic":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 5);
                    break;
                }

                case "security":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 6);
                    break;
                }

                case "lng-and-cds-production":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 9);
                    break;
                }

                case "plant-availability":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 10);
                    break;
                }

                case "safety":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 11);
                    break;
                }

                case "table-tank":
                case "global-stock-market":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 13);
                    var result = _selectService.GetHighlightTypesDropdown();
                    editViewModel.Highlights = result.Select(item => new SelectListItem()
                        {
                            Text = item.Text, Value = item.Value
                        }).ToList();
                    break;
                }

                case "economic-indicator":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 15);
                    break;
                }

                case "lng-and-cds":
                {
                    editViewModel.KpiInformations = AddEmptyKpiInformations(editViewModel.KpiInformations, 17);
                    break;
                }

                case "prepared-by":
                case "reviewed-by":
                {
                    editViewModel.SignedBy = response.SignedBy;
                    var result = _userService.GetUsers(new GetUsersRequest {
                            SortingDictionary = new Dictionary <string, SortOrder>(), Take = 1000
                        });
                    editViewModel.Users =
                        result.Users.Select(
                            item => new SelectListItem()
                        {
                            Text = item.Username, Value = item.Id.ToString()
                        }).ToList();
                    break;
                }
                }
                return(View("EditLayoutItem", editViewModel));

                #endregion
            }
            else
            {
                #region create
                viewModel.Types = _dropdownService.GetDerItemTypes().OrderBy(x => x.Text).MapTo <SelectListItem>();
                var rowCol = viewModel.Row.ToString() + "-and-" + viewModel.Column.ToString();
                switch (rowCol)
                {
                case "0-and-0":
                {
                    viewModel.Type = "avg-ytd-key-statistic";
                    break;
                };

                case "0-and-2":
                {
                    viewModel.Type = "speedometer";
                    break;
                }

                case "1-and-0":
                {
                    viewModel.Type = "multiaxis";
                    break;
                }

                case "1-and-1":
                case "1-and-2":
                case "1-and-3":
                {
                    viewModel.Type = "line";
                    break;
                }

                case "2-and-0":
                {
                    viewModel.Type = "dafwc";
                    break;
                }

                case "2-and-1":
                {
                    viewModel.Type = "weather";
                    break;
                }

                case "2-and-2":
                {
                    viewModel.Type = "wave";
                    break;
                }

                case "3-and-0":
                {
                    viewModel.Type = "safety";
                    break;
                }

                case "3-and-1":
                case "3-and-2":
                case "3-and-3":
                case "0-and-1":
                case "0-and-3":
                case "3-and-5":
                case "10-and-2":
                case "11-and-2":
                case "11-and-1":
                case "12-and-0":
                case "12-and-2":
                case "13-and-0":
                case "14-and-2":
                case "15-and-1":
                case "15-and-2":
                case "16-and-4":
                case "16-and-5":
                case "16-and-6":
                case "16-and-7":
                {
                    viewModel.Type = "highlight";
                    break;
                }

                case "3-and-4":
                {
                    viewModel.Type = "pie";
                    break;
                }

                case "4-and-0":
                {
                    viewModel.Type = "dafwc";
                    break;
                }

                case "4-and-1":
                {
                    viewModel.Type = "security";
                    break;
                }

                case "4-and-2":
                {
                    viewModel.Type = "alert";
                    break;
                }

                case "5-and-0":
                {
                    viewModel.Type = "job-pmts";
                    break;
                }

                case "5-and-1":
                {
                    viewModel.Type = "mgdp";
                    break;
                }

                case "5-and-2":
                {
                    viewModel.Type = "hhv";
                    break;
                }

                case "6-and-0":
                {
                    viewModel.Type = "total-feed-gas";
                    break;
                }

                case "6-and-2":
                {
                    viewModel.Type = "plant-availability";
                    break;
                }

                case "6-and-3":
                case "6-and-4":
                case "6-and-6":
                case "6-and-7":
                case "6-and-8":
                case "6-and-9":
                case "6-and-10":
                {
                    viewModel.Type = "barmeter";
                    break;
                }

                case "6-and-5":
                {
                    viewModel.Type = "termometer";
                    break;
                }

                case "7-and-0":
                {
                    viewModel.Type = "lng-and-cds-production";
                    break;
                }

                case "7-and-1":
                {
                    viewModel.Type = "lng-and-cds";
                    break;
                }

                case "8-and-0":
                case "8-and-1":
                case "8-and-2":
                case "8-and-3":
                {
                    viewModel.Type = "tank";
                    break;
                }

                case "8-and-4":
                {
                    viewModel.Type = "nls";
                    break;
                }

                case "9-and-0":
                {
                    viewModel.Type = "table-tank";
                    break;
                }

                case "10-and-0":
                {
                    viewModel.Type = "weekly-maintenance";
                    break;
                }

                case "10-and-1":
                {
                    viewModel.Type = "key-equipment-status";
                    break;
                }

                case "11-and-0":
                {
                    viewModel.Type = "critical-pm";
                    break;
                }

                case "12-and-1":
                {
                    viewModel.Type = "loading-duration";
                    break;
                }

                case "14-and-0":
                {
                    viewModel.Type = "procurement";
                    break;
                }

                case "15-and-0":
                {
                    viewModel.Type = "indicative-commercial-price";
                    break;
                }

                case "14-and-1":
                {
                    viewModel.Type = "economic-indicator";
                    break;
                }

                case "16-and-1":
                {
                    viewModel.Type = "global-stock-market";
                    break;
                }

                case "16-and-2":
                {
                    viewModel.Type = "prepared-by";
                    break;
                }

                case "16-and-3":
                {
                    viewModel.Type = "reviewed-by";
                    break;
                }

                case "15-and-3":
                {
                    viewModel.Type = "person-on-board";
                    break;
                }
                }
                return(View("LayoutItem", viewModel));

                #endregion
            }
        }