Exemple #1
0
        public DeleteMeasurementResponse Delete(int id)
        {
            var response = new DeleteMeasurementResponse();
            try
            {
                var measurement = new Measurement {Id = id};
                DataContext.Measurements.Attach(measurement);
                DataContext.Entry(measurement).State = EntityState.Deleted;
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "Measurement item has been deleted successfully";
            }
            catch (DbUpdateException dbUpdateException)
            {
                response.Message = dbUpdateException.Message;
            }

            return response;
        }
Exemple #2
0
        public UpdateArtifactResponse Update(UpdateArtifactRequest request)
        {
            var artifact = DataContext.Artifacts.Include(x => x.Measurement)
                .Include(x => x.Series)
                .Include(x => x.Series.Select(y => y.Kpi))
                .Include(x => x.Series.Select(y => y.Stacks))
                .Include(x => x.Series.Select(y => y.Stacks.Select(z => z.Kpi)))
                .Include(x => x.Plots)
                .Include(x => x.Rows)
                .Single(x => x.Id == request.Id);

            if (artifact.Measurement.Id != request.MeasurementId)
            {
                var measurement = new Measurement { Id = request.MeasurementId };
                DataContext.Measurements.Attach(measurement);
                artifact.Measurement = measurement;
            }

            foreach (var series in artifact.Series.ToList())
            {
                foreach (var stack in series.Stacks.ToList())
                {
                    DataContext.ArtifactStacks.Remove(stack);
                }
                DataContext.ArtifactSeries.Remove(series);
            }

            foreach (var plot in artifact.Plots.ToList())
            {
                DataContext.ArtifactPlots.Remove(plot);
            }

            foreach (var seriesReq in request.Series)
            {
                var series = seriesReq.MapTo<ArtifactSerie>();
                if (seriesReq.KpiId != 0)
                {
                    var kpi = new Kpi { Id = seriesReq.KpiId };
                    if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == seriesReq.KpiId) == null)
                    {
                        DataContext.Kpis.Attach(kpi);
                    }
                    else
                    {
                        kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == seriesReq.KpiId);
                    }
                    series.Kpi = kpi;
                }
                foreach (var stackReq in seriesReq.Stacks)
                {
                    var stack = stackReq.MapTo<ArtifactStack>();
                    if (stackReq.KpiId != 0)
                    {
                        var kpiInStack = new Kpi { Id = stackReq.KpiId };
                        if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == stackReq.KpiId) == null)
                        {
                            DataContext.Kpis.Attach(kpiInStack);
                        }
                        else
                        {
                            kpiInStack = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == stackReq.KpiId);
                        }
                        stack.Kpi = kpiInStack;
                    }
                    series.Stacks.Add(stack);
                }
                artifact.Series.Add(series);
            }

            foreach (var plotReq in request.Plots)
            {
                var plot = plotReq.MapTo<ArtifactPlot>();
                artifact.Plots.Add(plot);
            }

            foreach (var row in artifact.Rows.ToList())
            {
                DataContext.ArtifactRows.Remove(row);
            }

            foreach (var rowReq in request.Rows)
            {
                var row = rowReq.MapTo<ArtifactRow>();
                if (rowReq.KpiId != 0)
                {
                    var kpiInRow = new Kpi { Id = rowReq.KpiId };
                    if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == rowReq.KpiId) == null)
                    {
                        DataContext.Kpis.Attach(kpiInRow);
                    }
                    else
                    {
                        kpiInRow = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == rowReq.KpiId);
                    }
                    row.Kpi = kpiInRow;
                }
                artifact.Rows.Add(row);
            }

            if (request.Tank != null)
            {
                var tank = DataContext.ArtifactTanks.Single(x => x.Id == request.Tank.Id);
                var volumeInventory = new Kpi { Id = request.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.Tank.VolumeInventoryId);
                }
                tank.VolumeInventory = volumeInventory;
                var daysToTankTop = new Kpi { Id = request.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.Tank.DaysToTankTopId);
                }
                tank.DaysToTankTop = daysToTankTop;
                tank.DaysToTankTopTitle = request.Tank.DaysToTankTopTitle;
                tank.MinCapacity = request.Tank.MinCapacity;
                tank.MaxCapacity = request.Tank.MaxCapacity;
            }

            artifact.GraphicName = request.GraphicName;
            artifact.HeaderTitle = request.HeaderTitle;
            artifact.PeriodeType = request.PeriodeType;
            artifact.RangeFilter = request.RangeFilter;
            artifact.Start = request.Start;
            artifact.End = request.End;
            artifact.ValueAxis = request.ValueAxis;
            artifact.Actual = request.Actual;
            artifact.Target = request.Target;
            artifact.Economic = request.Economic;
            artifact.Fullfillment = request.Fullfillment;
            artifact.Remark = request.Remark;

            artifact.FractionScale = request.FractionScale;

            DataContext.SaveChanges();
            return new UpdateArtifactResponse();
        }
Exemple #3
0
        public CreateArtifactResponse Create(CreateArtifactRequest request)
        {
            var artifact = request.MapTo<Artifact>();
            var measurement = new Measurement { Id = request.MeasurementId };
            DataContext.Measurements.Attach(measurement);
            artifact.Measurement = measurement;

            foreach (var seriesReq in request.Series)
            {
                var series = seriesReq.MapTo<ArtifactSerie>();
                if (seriesReq.KpiId != 0)
                {
                    var kpi = new Kpi { Id = seriesReq.KpiId };
                    if (DataContext.Kpis.Local.Where(x => x.Id == seriesReq.KpiId).FirstOrDefault() == null)
                    {
                        DataContext.Kpis.Attach(kpi);
                    }
                    else
                    {
                        kpi = DataContext.Kpis.Local.Where(x => x.Id == seriesReq.KpiId).FirstOrDefault();
                    }
                    series.Kpi = kpi;
                }
                foreach (var stackReq in seriesReq.Stacks)
                {
                    var stack = stackReq.MapTo<ArtifactStack>();
                    if (stackReq.KpiId != 0)
                    {
                        var kpiInStack = new Kpi { Id = stackReq.KpiId };
                        if (DataContext.Kpis.Local.Where(x => x.Id == stackReq.KpiId).FirstOrDefault() == null)
                        {
                            DataContext.Kpis.Attach(kpiInStack);
                        }
                        else
                        {
                            kpiInStack = DataContext.Kpis.Local.Where(x => x.Id == stackReq.KpiId).FirstOrDefault();
                        }
                        stack.Kpi = kpiInStack;
                    }
                    series.Stacks.Add(stack);
                }
                artifact.Series.Add(series);
            }
            foreach (var plotReq in request.Plots)
            {
                var plot = plotReq.MapTo<ArtifactPlot>();
                artifact.Plots.Add(plot);
            }
            foreach (var rowReq in request.Rows)
            {
                var row = rowReq.MapTo<ArtifactRow>();
                if (rowReq.KpiId != 0)
                {
                    var kpiInRow = new Kpi { Id = rowReq.KpiId };
                    if (DataContext.Kpis.Local.Where(x => x.Id == rowReq.KpiId).FirstOrDefault() == null)
                    {
                        DataContext.Kpis.Attach(kpiInRow);
                    }
                    else
                    {
                        kpiInRow = DataContext.Kpis.Local.Where(x => x.Id == rowReq.KpiId).FirstOrDefault();
                    }
                    row.Kpi = kpiInRow;
                }
                artifact.Rows.Add(row);
            }
            if (request.Tank != null)
            {
                var tank = new ArtifactTank();
                var volumeInventory = new Kpi { Id = request.Tank.VolumeInventoryId };
                if (DataContext.Kpis.Local.Where(x => x.Id == volumeInventory.Id).FirstOrDefault() == null)
                {
                    DataContext.Kpis.Attach(volumeInventory);
                }
                else
                {
                    volumeInventory = DataContext.Kpis.Local.Where(x => x.Id == request.Tank.VolumeInventoryId).FirstOrDefault();
                }
                tank.VolumeInventory = volumeInventory;
                var daysToTankTop = new Kpi { Id = request.Tank.DaysToTankTopId };
                if (DataContext.Kpis.Local.Where(x => x.Id == daysToTankTop.Id).FirstOrDefault() == null)
                {
                    DataContext.Kpis.Attach(daysToTankTop);
                }
                else
                {
                    daysToTankTop = DataContext.Kpis.Local.Where(x => x.Id == request.Tank.DaysToTankTopId).FirstOrDefault();
                }
                tank.DaysToTankTop = daysToTankTop;
                tank.DaysToTankTopTitle = request.Tank.DaysToTankTopTitle;
                tank.MinCapacity = request.Tank.MinCapacity;
                tank.MaxCapacity = request.Tank.MaxCapacity;
                artifact.Tank = tank;
            }
            DataContext.Artifacts.Add(artifact);
            DataContext.SaveChanges();
            return new CreateArtifactResponse();
        }
Exemple #4
0
 public SaveVesselResponse SaveVessel(SaveVesselRequest request)
 {
     try
     {
         if (request.Id == 0)
         {
             var vessel = request.MapTo<Vessel>();
             var measurement = new Measurement { Id = request.MeasurementId };
             DataContext.Measurements.Attach(measurement);
             vessel.Measurement = measurement;
             DataContext.Vessels.Add(vessel);
         }
         else
         {
             var vessel = DataContext.Vessels.FirstOrDefault(x => x.Id == request.Id);
             if (vessel != null)
             {
                 request.MapPropertiesToInstance<Vessel>(vessel);
                 var measurement = new Measurement { Id = request.MeasurementId };
                 DataContext.Measurements.Attach(measurement);
                 vessel.Measurement = measurement;
             }
         }
         DataContext.SaveChanges();
         return new SaveVesselResponse
         {
             IsSuccess = true,
             Message = "Vessel has been saved"
         };
     }
     catch (InvalidOperationException e)
     {
         return new SaveVesselResponse
         {
             IsSuccess = false,
             Message = e.Message
         };
     }
 }
Exemple #5
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;
        }
Exemple #6
0
        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;
        }
Exemple #7
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;
        }
Exemple #8
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;
        }
Exemple #9
0
        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;
        }
Exemple #10
0
        public SaveOutputConfigResponse Save(SaveOutputConfigRequest request)
        {
            try
            {
                var outputConfig = request.MapTo<KeyOutputConfiguration>();
                if (request.Id != 0)
                {
                    outputConfig = DataContext.KeyOutputConfigs.Include(x => x.Measurement)
                        .Include(x => x.Category)
                       .Include(x => x.Kpis)
                       .Include(x => x.KeyAssumptions)
                       .First(x => x.Id == request.Id);
                    request.MapPropertiesToInstance<KeyOutputConfiguration>(outputConfig);
                    foreach (var kpi in outputConfig.Kpis.ToList())
                    {
                        outputConfig.Kpis.Remove(kpi);
                    }
                    foreach (var assumption in outputConfig.KeyAssumptions.ToList())
                    {
                        outputConfig.KeyAssumptions.Remove(assumption);
                    }
                    outputConfig.Measurement = DataContext.Measurements.FirstOrDefault(x => x.Id == request.MeasurementId);
                    if (request.CategoryId != outputConfig.Category.Id)
                    {
                        var category = new KeyOutputCategory { Id = request.CategoryId };
                        DataContext.KeyOutputCategories.Attach(category);
                        outputConfig.Category = category;
                    }

                }
                else
                {
                    if (request.MeasurementId != 0)
                    {
                        var measurement = new Measurement { Id = request.MeasurementId };
                        DataContext.Measurements.Attach(measurement);
                        outputConfig.Measurement = measurement;
                    }
                    var category = new KeyOutputCategory { Id = request.CategoryId };
                    DataContext.KeyOutputCategories.Attach(category);
                    outputConfig.Category = category;

                    DataContext.KeyOutputConfigs.Add(outputConfig);
                }
                foreach (var kpiId in request.KpiIds)
                {
                    var kpi = new Kpi { Id = kpiId };
                    if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId) == null)
                    {
                        DataContext.Kpis.Attach(kpi);
                    }
                    else
                    {
                        kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                    }
                    outputConfig.Kpis.Add(kpi);
                }
                foreach (var assumptionId in request.KeyAssumptionIds)
                {
                    var assumption = new KeyAssumptionConfig { Id = assumptionId };
                    if (DataContext.KeyAssumptionConfigs.Local.FirstOrDefault(x => x.Id == assumptionId) == null)
                    {
                        DataContext.KeyAssumptionConfigs.Attach(assumption);
                    }
                    else
                    {
                        assumption = DataContext.KeyAssumptionConfigs.Local.FirstOrDefault(x => x.Id == assumptionId);
                    }
                    outputConfig.KeyAssumptions.Add(assumption);
                }
                DataContext.SaveChanges();
                return new SaveOutputConfigResponse
                {
                    IsSuccess = true,
                    Message = "The item has been saved successfully"
                };
            }
            catch
            {
                return new SaveOutputConfigResponse
                {
                    IsSuccess = false,
                    Message = "An Error Occured please contact the administrator for further information"
                };
            }
        }
Exemple #11
0
        public void Install()
        {
            var meas1 = new Measurement {
                Id = 1,
                Name = "tbtu",
                IsActive = true
            };
            var meas2 = new Measurement
            {
                Id = 2,
                Name = "MMSCF",
                IsActive = true
            };

            var meas3 = new Measurement
            {
                Id = 3,
                Name = "MT",
                IsActive = true
            };
            var meas4 = new Measurement
            {
                Id = 4,
                Name = "%",
                IsActive = true
            };
            var meas5 = new Measurement
            {
                Id = 5,
                Name = "days",
                IsActive = true
            };
            var meas6 = new Measurement
            {
                Id = 6,
                Name = "Case",
                IsActive = true
            };
            var meas7 = new Measurement
            {
                Id = 7,
                Name = "Cargo",
                IsActive = true
            };
            var meas8 = new Measurement
            {
                Id = 8,
                Name = "USD(Mio)",
                IsActive = true
            };
            var meas9 = new Measurement
            {
                Id = 9,
                Name = "Times",
                IsActive = true
            };
            var meas10 = new Measurement
            {
                Id = 10,
                Name = "USD/mmbtu",
                IsActive = true
            };
            var meas11 = new Measurement
            {
                Id = 11,
                Name = "Number",
                IsActive = true
            };
            var meas12 = new Measurement
            {
                Id = 12,
                Name = "USD/pax",
                IsActive = true
            };
            var meas13 = new Measurement
            {
                Id = 13,
                Name = "USD",
                IsActive = true
            };
            var meas14 = new Measurement
            {
                Id = 14,
                Name = "hour",
                IsActive = true
            };
            var meas15 = new Measurement
            {
                Id = 15,
                Name = "MMSCFD",
                IsActive = true
            };
            var meas16 = new Measurement
            {
                Id = 16,
                Name = "MMBBL",
                IsActive = true
            };
            var meas17 = new Measurement
            {
                Id = 17,
                Name = "USD/bbl",
                IsActive = true
            };

            _context.Measurements.Add(meas1);
            _context.Measurements.Add(meas2);
            _context.Measurements.Add(meas3);
            _context.Measurements.Add(meas4);
            _context.Measurements.Add(meas5);
            _context.Measurements.Add(meas6);
            _context.Measurements.Add(meas7);
            _context.Measurements.Add(meas8);
            _context.Measurements.Add(meas9);
            _context.Measurements.Add(meas10);
            _context.Measurements.Add(meas11);
            _context.Measurements.Add(meas12);
            _context.Measurements.Add(meas13);
            _context.Measurements.Add(meas14);
            _context.Measurements.Add(meas15);
            _context.Measurements.Add(meas16);
            _context.Measurements.Add(meas17);
        }