Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        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;
        }