private BaseResponse SaveMultiAxis(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = request.MapTo<DerLayoutItem>();// new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; //derLayoutItem.Column = request.Column; //derLayoutItem.Row = request.Row; //derLayoutItem.Type = request.Type; var derArtifact = request.MapTo<DerArtifact>(); //derArtifact.GraphicType = request.Type; //derArtifact.HeaderTitle = request.Artifact.HeaderTitle; /*var measurement = new Measurement { Id = request.Artifact.MeasurementId }; DataContext.Measurements.Attach(measurement); derArtifact.Measurement = measurement;*/ derArtifact.Charts = new List<DerArtifactChart>(); foreach (var item in request.Artifact.MultiAxis.Charts) { var chart = item.MapTo<DerArtifactChart>(); var measurement = new Measurement { Id = item.MeasurementId }; if (DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id) == null) { DataContext.Measurements.Attach(measurement); } else { measurement = DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id); } DataContext.Measurements.Attach(measurement); chart.Measurement = measurement; foreach (var s in item.Series) { var serie = s.MapTo<DerArtifactSerie>(); var kpi = new Kpi { Id = s.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } serie.Kpi = kpi; serie.Artifact = derArtifact; chart.Series.Add(serie); } derArtifact.Charts.Add(chart); } derLayoutItem.Artifact = derArtifact; //DataContext.DerArtifacts.Add(derArtifact); DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Multiaxis has been configured"; /*var charts = request.Artifact.MultiAxis.Charts.Select(x => new DerArtifactChart { FractionScale = x.FractionScale, GraphicType = x.GraphicType, IsOpposite = x.IsOpposite, MaxFractionScale = x.MaxFractionScale, Measurement = DataContext.Measurements.Single(x => x.) })*/ /* var series = request.Artifact.LineChart.Series.Select(x => new DerArtifactSerie { Color = x.Color, Kpi = DataContext.Kpis.FirstOrDefault(y => y.Id == x.KpiId), Label = x.Label }).ToList(); derArtifact.Series = series; DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; DataContext.DerLayoutItems.Add(derLayoutItem);*/ } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveKpiInformations(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var kpiInformations = new List<DerKpiInformation>(); foreach (var item in request.KpiInformations) { if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } kpiInformations.Add(new DerKpiInformation { Kpi = kpi, Position = item.Position, IsOriginalData = item.IsOriginalData, ConfigType = item.ConfigType }); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, IsOriginalData = item.IsOriginalData, ConfigType = item.ConfigType }); } } derLayoutItem.KpiInformations = kpiInformations; DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveLineChart(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact(); derArtifact.GraphicType = request.Type; derArtifact.HeaderTitle = request.Artifact.HeaderTitle; var measurement = new Measurement { Id = request.Artifact.MeasurementId }; DataContext.Measurements.Attach(measurement); derArtifact.Measurement = measurement; var series = request.Artifact.LineChart.Series.Select(x => new DerArtifactSerie { Color = x.Color, Kpi = DataContext.Kpis.FirstOrDefault(y => y.Id == x.KpiId), Label = x.Label, Artifact = derArtifact }).ToList(); derArtifact.Series = series; DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveDafwc(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { if (request.Id > 0) { } else { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; DataContext.DerLayoutItems.Add(derLayoutItem); } DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveHighlight(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derHiglight = new DerHighlight(); var selectOption = new SelectOption { Id = request.Highlight.SelectOptionId }; DataContext.SelectOptions.Attach(selectOption); derHiglight.SelectOption = selectOption; derLayoutItem.Highlight = derHiglight; DataContext.DerHighlights.Add(derHiglight); DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdatePie(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = DataContext.DerLayoutItems .Include(x => x.Artifact) .Include(x => x.Artifact.Measurement) .Include(x => x.Artifact.Series) .Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact(); derArtifact.ShowLegend = request.Artifact.ShowLegend; derArtifact.Is3D = request.Artifact.Is3D; derArtifact.HeaderTitle = request.Artifact.HeaderTitle; derArtifact.GraphicType = request.Type; derArtifact.Charts = new List<DerArtifactChart>(); var measurement = new Measurement { Id = request.Artifact.MeasurementId }; if (DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id) == null) { DataContext.Measurements.Attach(measurement); } else { measurement = DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id); } derArtifact.Measurement = measurement; var series = request.Artifact.Pie.Series.Select(x => new DerArtifactSerie { Color = x.Color, Kpi = DataContext.Kpis.FirstOrDefault(y => y.Id == x.KpiId), Artifact = derArtifact }).ToList(); derArtifact.Series = series; DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; //DataContext.DerLayoutItems.Add(derLayoutItem); var oldArtifact = new DerArtifact { Id = request.Artifact.Id }; if (DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id) == null) { DataContext.DerArtifacts.Attach(oldArtifact); } else { oldArtifact = DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id); } DataContext.DerArtifacts.Remove(oldArtifact); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateTank(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = DataContext.DerLayoutItems .Include(x => x.Artifact) .Include(x => x.Artifact.Tank) .Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact();//request.MapTo<DerArtifact>(); derArtifact.HeaderTitle = request.Artifact.HeaderTitle; derArtifact.GraphicType = request.Type; derLayoutItem.Artifact = derArtifact; derLayoutItem.Artifact.Tank = request.Artifact.Tank.MapTo<DerArtifactTank>(); var volumeInventory = new Kpi { Id = request.Artifact.Tank.VolumeInventoryId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == volumeInventory.Id) == null) { DataContext.Kpis.Attach(volumeInventory); } else { volumeInventory = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == request.Artifact.Tank.VolumeInventoryId); } var daysToTankTop = new Kpi { Id = request.Artifact.Tank.DaysToTankTopId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == daysToTankTop.Id) == null) { DataContext.Kpis.Attach(daysToTankTop); } else { daysToTankTop = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == request.Artifact.Tank.DaysToTankTopId); } derLayoutItem.Artifact.Tank.VolumeInventory = volumeInventory; derLayoutItem.Artifact.Tank.DaysToTankTop = daysToTankTop; DataContext.DerArtifacts.Add(derArtifact); //DataContext.DerLayoutItems.Add(derLayoutItem); var oldArtifact = new DerArtifact { Id = request.Artifact.Id }; if (DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id) == null) { DataContext.DerArtifacts.Attach(oldArtifact); } else { oldArtifact = DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id); } DataContext.DerArtifacts.Remove(oldArtifact); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SavePie(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = request.MapTo<DerArtifact>(); derArtifact.ShowLegend = request.Artifact.ShowLegend; derArtifact.Is3D = request.Artifact.Is3D; derArtifact.Charts = new List<DerArtifactChart>(); var measurement = new Measurement { Id = request.Artifact.MeasurementId }; DataContext.Measurements.Attach(measurement); derArtifact.Measurement = measurement; var series = request.Artifact.Pie.Series.Select(x => new DerArtifactSerie { Color = x.Color, Kpi = DataContext.Kpis.FirstOrDefault(y => y.Id == x.KpiId), Artifact = derArtifact }).ToList(); derArtifact.Series = series; DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateMultiAxis(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = DataContext.DerLayoutItems .Include(x => x.Artifact) .Include(x => x.Artifact.Measurement) .Include(x => x.Artifact.Series) .Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact(); derArtifact.GraphicType = request.Type; derArtifact.HeaderTitle = request.Artifact.HeaderTitle; /*var measurement = new Measurement { Id = request.Artifact.MeasurementId }; DataContext.Measurements.Attach(measurement); derArtifact.Measurement = measurement;*/ derArtifact.Charts = new List<DerArtifactChart>(); foreach (var item in request.Artifact.MultiAxis.Charts) { var chart = item.MapTo<DerArtifactChart>(); var measurement = new Measurement { Id = item.MeasurementId }; if (DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id) == null) { DataContext.Measurements.Attach(measurement); } else { measurement = DataContext.Measurements.Local.FirstOrDefault(x => x.Id == measurement.Id); } DataContext.Measurements.Attach(measurement); chart.Measurement = measurement; foreach (var s in item.Series) { var serie = s.MapTo<DerArtifactSerie>(); var kpi = new Kpi { Id = s.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } serie.Kpi = kpi; serie.Artifact = derArtifact; chart.Series.Add(serie); } derArtifact.Charts.Add(chart); } derLayoutItem.Artifact = derArtifact; //DataContext.DerArtifacts.Add(derArtifact); //DataContext.DerLayoutItems.Add(derLayoutItem); var oldArtifact = DataContext.DerArtifacts .Include(x => x.Charts) .Include(x => x.Charts.Select(y => y.Series)) .Single(x => x.Id == request.Artifact.Id); foreach (var chart in oldArtifact.Charts.ToList()) { foreach (var series in chart.Series.ToList()) { DataContext.DerArtifactSeries.Remove(series); } DataContext.DerArtifactCharts.Remove(chart); } DataContext.DerArtifacts.Remove(oldArtifact); DataContext.SaveChanges(); } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateUser(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = DataContext.DerLayoutItems.Include(x => x.KpiInformations).Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; derLayoutItem.SignedBy = DataContext.Users.Single(x => x.Id == request.SignedBy); DataContext.Entry(derLayoutItem).State = EntityState.Modified; DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateSpeedometer(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = DataContext.DerLayoutItems .Include(x => x.Artifact) .Include(x => x.Artifact.Plots) .Include(x => x.Artifact.CustomSerie) .Include(x => x.Artifact.Series) .Single(x => x.Id == request.Id); //DataContext.DerArtifacts.Remove(derLayoutItem.Artifact); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact(); derArtifact.GraphicType = request.Type; var plots = request.Artifact.Speedometer.PlotBands.Select(x => new DerArtifactPlot { Color = x.Color, From = x.From, To = x.To }).ToList(); derArtifact.Plots = plots; derArtifact.CustomSerie = DataContext.Kpis.FirstOrDefault(y => y.Id == request.Artifact.Speedometer.Series.KpiId); if (request.Artifact.Speedometer.LabelSeries != null) { if (derArtifact.Series != null) { foreach (var serie in derArtifact.Series.ToList()) { derArtifact.Series.Remove(serie); } } else { derArtifact.Series = new List<DerArtifactSerie>(); } var labelSeries = new DerArtifactSerie { Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == request.Artifact.Speedometer.LabelSeries.KpiId), Label = "tonnes/day", Color = "#000" }; derArtifact.Series.Add(labelSeries); } DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; //DataContext.DerLayoutItems.Add(derLayoutItem); var oldArtifact = new DerArtifact { Id = request.Artifact.Id }; if (DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id) == null) { DataContext.DerArtifacts.Attach(oldArtifact); } else { oldArtifact = DataContext.DerArtifacts.Local.FirstOrDefault(x => x.Id == oldArtifact.Id); } foreach(var plot in oldArtifact.Plots.ToList()) { DataContext.DerArtifactPlots.Remove(plot); } DataContext.DerArtifacts.Remove(oldArtifact); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateKpiInformations(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = DataContext.DerLayoutItems.Include(x => x.KpiInformations).Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var kpiInformations = new List<DerKpiInformation>(); foreach (var item in request.KpiInformations) { var kpiInformation = DataContext.DerKpiInformations.SingleOrDefault(x => x.Id == item.Id); if (kpiInformation != null) { DataContext.DerKpiInformations.Remove(kpiInformation); } if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } /*if (kpiInformation != null) { DataContext.DerKpiInformations.Remove(kpiInformation); if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } } else { if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); //kpiInformations.Add(new DerKpiInformation { Kpi = kpi, Position = item.Position, ConfigType = item.ConfigType, KpiLabel = item.KpiLabel, KpiMeasurement = item.KpiMeasurement}); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } }*/ } derLayoutItem.KpiInformations = kpiInformations; //DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.Entry(derLayoutItem).State = EntityState.Modified; DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveUser(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; derLayoutItem.SignedBy = DataContext.Users.Single(x => x.Id == request.SignedBy); DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveSpeedometer(SaveLayoutItemRequest request) { var response = new BaseResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derArtifact = new DerArtifact(); derArtifact.GraphicType = request.Type; var plots = request.Artifact.Speedometer.PlotBands.Select(x => new DerArtifactPlot { Color = x.Color, From = x.From, To = x.To }).ToList(); derArtifact.Plots = plots; derArtifact.CustomSerie = DataContext.Kpis.FirstOrDefault(y => y.Id == request.Artifact.Speedometer.Series.KpiId); if (request.Artifact.Speedometer.LabelSeries != null) { var labelSeries = new DerArtifactSerie { Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == request.Artifact.Speedometer.LabelSeries.KpiId), Label = "ton/d", Color = "#000" }; derArtifact.Series = new List<DerArtifactSerie>(); derArtifact.Series.Add(labelSeries); } DataContext.DerArtifacts.Add(derArtifact); derLayoutItem.Artifact = derArtifact; DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }