Ejemplo n.º 1
0
        public SaveMirDataTableResponse SaveMirDataTableRespons(SaveMirDataTableRequest request)
        {
            var MirDataTable = request.MapTo<MirDataTable>();
            if (request.MirDataId == 0)
            {
                MirDataTable.MirConfiguration = DataContext.MirConfigurations.FirstOrDefault(x => x.Id == request.MirConfigurationId);
                DataContext.MirDataTables.Add(MirDataTable);
                DataContext.SaveChanges();
                //MirDataTable.Kpis = new List<Kpi>();
                foreach(var kpiId in request.KpiIds)
                {
                    var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                    if (kpi == null )
                    {
                        kpi = new Kpi { Id = kpiId };
                        DataContext.Kpis.Attach(kpi);
                    }
                    DataContext.MirTableKpis.Add(new MirTableKpi { Kpi = kpi, MirTable = MirDataTable });
                    //MirDataTable.Kpis.Add(kpi);
                }

            }
            else
            {
                MirDataTable = DataContext.MirDataTables.Include(x => x.Kpis).FirstOrDefault(x => x.Id == request.MirDataId);
                request.MapPropertiesToInstance<MirDataTable>(MirDataTable);
                foreach (var mirTableKpi in MirDataTable.Kpis.ToList()) {
                    MirDataTable.Kpis.Remove(mirTableKpi);
                }

                //MirDataTable.Kpis = new List<Kpi>();
                foreach(var kpiId in request.KpiIds)
                {
                    var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                    if(kpi == null)
                    {
                        kpi = new Kpi { Id = kpiId };
                        DataContext.Kpis.Attach(kpi);
                    }
                    DataContext.MirTableKpis.Add(new MirTableKpi { Kpi = kpi, MirTable = MirDataTable });
                    //MirDataTable.Kpis.Add(kpi);
                }
            }

            DataContext.SaveChanges();

            return new SaveMirDataTableResponse
            {
                KpiIds = MirDataTable.Kpis.Select(x => x.Id).ToArray(),
                IsSuccess = true,
                Message = "Mir Data Table has been saved succesfully"
            };
        }
Ejemplo n.º 2
0
        public SaveMirDataTableResponse SaveMirDataTableRespons(SaveMirDataTableRequest request)
        {
            var MirDataTable = request.MapTo<MirDataTable>();
            if (request.MirDataId == 0)
            {
                MirDataTable.MirConfiguration = DataContext.MirConfigurations.FirstOrDefault(x => x.Id == request.MirConfigurationId);
                MirDataTable.Kpis = new List<Kpi>();
                foreach(var kpiId in request.KpiIds)
                {
                    var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                    if (kpi == null )
                    {
                        kpi = new Kpi { Id = kpiId };
                        DataContext.Kpis.Attach(kpi);
                    }
                    MirDataTable.Kpis.Add(kpi);
                }
                DataContext.MirDataTables.Add(MirDataTable);
            }
            else
            {
                MirDataTable = DataContext.MirDataTables.FirstOrDefault(x => x.Id == request.MirDataId);
                request.MapPropertiesToInstance<MirDataTable>(MirDataTable);
                MirDataTable.Kpis = new List<Kpi>();
                foreach(var kpiId in request.KpiIds)
                {
                    var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                    if(kpi == null)
                    {
                        kpi = new Kpi { Id = kpiId };
                        DataContext.Kpis.Attach(kpi);
                    }
                    MirDataTable.Kpis.Add(kpi);
                }
            }

            DataContext.SaveChanges();

            return new SaveMirDataTableResponse
            {
                IsSuccess = true,
                Message = "Mir Data Table has been saved succesfully"
            };
        }
Ejemplo n.º 3
0
 public SaveKpiTransformationLogResponse Save(SaveKpiTransformationLogRequest request)
 {
     var kpiTransformationLog = request.MapTo<KpiTransformationLog>();
     var kpiTransformationSchedule = DataContext.KpiTransformationSchedules.Local.FirstOrDefault(x => x.Id == request.KpiTransformationScheduleId);
     if (kpiTransformationSchedule == null) {
         kpiTransformationSchedule = new KpiTransformationSchedule { Id = request.KpiTransformationScheduleId };
         DataContext.KpiTransformationSchedules.Attach(kpiTransformationSchedule);
     }
     kpiTransformationLog.Schedule = kpiTransformationSchedule;
     var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == request.KpiId);
     if (kpi == null) {
         kpi = new Kpi { Id = request.KpiId };
         DataContext.Kpis.Attach(kpi);
     }
     kpiTransformationLog.Kpi = kpi;
     DataContext.KpiTransformationLogs.Add(kpiTransformationLog);
     DataContext.SaveChanges();
     return new SaveKpiTransformationLogResponse { IsSuccess = true, Message = "You have been successfully saved kpi transformation log" };
 }
Ejemplo n.º 4
0
        private void AddKpi()
        {
            var list = new Collection<KpiRelationModel>();
            var plantAvailability = _dataContext.Kpis.First(x => x.Id == 3);
            var item1 = new KpiRelationModel();
            item1.Kpi = plantAvailability;
            item1.Method = "Quantitative";
            list.Add(item1);

            var plantReliability = new Kpi
            {
                Name = "Plant Reliability",
                Measurement = _dataContext.Measurements.First(x => x.Id == 1),
                Pillar = _dataContext.Pillars.First(x => x.Id == 2),
                Order = 2,
                RelationModels = list
            };

            _dataContext.Kpis.Add(plantReliability);
            //_dataContext.Entry(plantReliability).State = System.Data.Entity.EntityState.Detached;
            _dataContext.SaveChanges();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public void Install()
        {
            var kpi1 = new Kpi { Id = 1, Code = "SECOR001QHSE", Name = "Fatality/Strap disability", Measurement = _context.Measurements.Local.First(x => x.Id == 6), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 1), Order = 1, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493865394), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi2 = new Kpi { Id = 2, Code = "SECOR002QHSE", Name = "DAFWC", Measurement = _context.Measurements.Local.First(x => x.Id == 6), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 2), Order = 2, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493872685), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi3 = new Kpi { Id = 3, Code = "SECOR003QHSE", Name = "LOPC", Measurement = _context.Measurements.Local.First(x => x.Id == 6), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 3), Order = 3, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.349387963), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi4 = new Kpi { Id = 4, Code = "SECOR004QHSE", Name = "Security Incident", Measurement = _context.Measurements.Local.First(x => x.Id == 6), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 4), Order = 4, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493887731), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi5 = new Kpi { Id = 5, Code = "PECOR005", Name = "Total LNG Production(MT)", Measurement = _context.Measurements.Local.First(x => x.Id == 3), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 5), Order = 5, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493894676), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 2), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi6 = new Kpi { Id = 6, Code = "PECOR001", Name = "Total LNG Production(tbtu)", Measurement = _context.Measurements.Local.First(x => x.Id == 1), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 5), Order = 6, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.349390162), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 2), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi7 = new Kpi { Id = 7, Code = "PECOR007COO ", Name = "Flared Gas(%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 6), Order = 7, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493908565), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 2), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi8 = new Kpi { Id = 8, Code = "PECOR007", Name = "Flared Gas(MMBTU)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 6), Order = 8, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493915162), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 4), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi9 = new Kpi { Id = 9, Code = "PECOR009COO ", Name = "Thermal Efficiency", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 7), Order = 9, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493922106), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 2), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi10 = new Kpi { Id = 10, Code = "PECOR010CTD ", Name = "Plant Availability(%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 8), Order = 10, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493928587), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 4), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi11 = new Kpi { Id = 11, Code = "PECOR010CTD ", Name = "Plant Availability(days)", Measurement = _context.Measurements.Local.First(x => x.Id == 5), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 8), Order = 11, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493935185), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 4), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi12 = new Kpi { Id = 12, Code = "PECOR012CTD ", Name = "Plant Reliability(%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 9), Order = 12, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.349394213), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 4), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi13 = new Kpi { Id = 13, Code = "PECOR013", Name = "Plant Reliability(days)", Measurement = _context.Measurements.Local.First(x => x.Id == 5), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 9), Order = 13, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493949074), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 4), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi14 = new Kpi { Id = 14, Code = "PECOR014CCD ", Name = "Cargo Commitment(Cargo)", Measurement = _context.Measurements.Local.First(x => x.Id == 7), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 10), Order = 14, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493955671), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 5), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi15 = new Kpi { Id = 15, Code = "PECOR015", Name = "Cargo Commitment(tbtu)", Measurement = _context.Measurements.Local.First(x => x.Id == 1), Pillar = _context.Pillars.Local.First(x => x.Id == 2), Group = _context.Groups.Local.First(x => x.Id == 10), Order = 15, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493962616), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 5), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi16 = new Kpi { Id = 16, Code = "FSCOR016CFD ", Name = "Dividend Payout Ratio", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 11), Order = 16, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493969097), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi17 = new Kpi { Id = 17, Code = "FSCOR017CFD ", Name = "Debt Service Coverage Ratio", Measurement = _context.Measurements.Local.First(x => x.Id == 9), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 12), Order = 17, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493976042), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi18 = new Kpi { Id = 18, Code = "FSCOR018CFD ", Name = "EBITDA", Measurement = _context.Measurements.Local.First(x => x.Id == 8), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 13), Order = 18, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493981482), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi19 = new Kpi { Id = 19, Code = "FSCOR019CFD ", Name = "Budget Utilization(%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 14), Order = 19, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493988426), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi20 = new Kpi { Id = 20, Code = "FSCOR005", Name = "Budget Utilization(USD Mio)", Measurement = _context.Measurements.Local.First(x => x.Id == 8), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 14), Order = 20, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Money, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3493996181), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi21 = new Kpi { Id = 21, Code = "FSCOR021CFD ", Name = "Total Operating Cost", Measurement = _context.Measurements.Local.First(x => x.Id == 10), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 15), Order = 21, YtdFormula = Enums.YtdFormula.Average, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494004282), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi22 = new Kpi { Id = 22, Code = "FSCOR022CFD ", Name = "Production Cost", Measurement = _context.Measurements.Local.First(x => x.Id == 10), Pillar = _context.Pillars.Local.First(x => x.Id == 3), Group = _context.Groups.Local.First(x => x.Id == 16), Order = 22, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494010764), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 3), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi23 = new Kpi { Id = 23, Code = "SRCOR023CSR ", Name = "Positive Tone", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 17), Order = 23, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494017708), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 12), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi24 = new Kpi { Id = 24, Code = "SRCOR024CSR ", Name = "Program recognized by Gov &amp; Institution", Measurement = _context.Measurements.Local.First(x => x.Id == 11), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 18), Order = 24, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494024653), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 12), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi25 = new Kpi { Id = 25, Code = "SRCOR025CSR ", Name = "Community acceptance through CSR program &amp; CR", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 19), Order = 25, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494031597), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 12), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi26 = new Kpi { Id = 26, Code = "SRCOR026CSR ", Name = "Social ROI", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 20), Order = 26, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494038542), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 12), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi27 = new Kpi { Id = 27, Code = "SRCOR027HCM ", Name = "EBITDA/Employee", Measurement = _context.Measurements.Local.First(x => x.Id == 13), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 21), Order = 27, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494045486), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 8), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi28 = new Kpi { Id = 28, Code = "SRCOR028CAD ", Name = "Cost/POB (USD/pax)", Measurement = _context.Measurements.Local.First(x => x.Id == 12), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 22), Order = 28, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494052431), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 6), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi29 = new Kpi { Id = 29, Code = "SRCOR029HCM ", Name = "Employee Retention (%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 23), Order = 29, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494059028), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 8), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi30 = new Kpi { Id = 30, Code = "SRCOR030HCM ", Name = "Employee Retention (#)", Measurement = _context.Measurements.Local.First(x => x.Id == 11), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 23), Order = 30, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494065972), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 8), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi31 = new Kpi { Id = 31, Code = "SRCOR031HRD ", Name = "Employee Turn over (%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 24), Order = 31, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494072917), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 8), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi32 = new Kpi { Id = 32, Code = "SRCOR032HCM ", Name = "Employee Turn over (#)", Measurement = _context.Measurements.Local.First(x => x.Id == 11), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 24), Order = 32, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494079861), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 8), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi33 = new Kpi { Id = 33, Code = "SRCOR033ICT ", Name = "ICT service availability", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 4), Group = _context.Groups.Local.First(x => x.Id == 25), Order = 33, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494086806), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 11), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi34 = new Kpi { Id = 34, Code = "SECOR034QHS ", Name = "QHSE training attend(%)", Measurement = _context.Measurements.Local.First(x => x.Id == 4), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 26), Order = 34, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41986.3494094907), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };
            var kpi35 = new Kpi { Id = 35, Code = "SECOR040QHS ", Name = "RIF", Measurement = _context.Measurements.Local.First(x => x.Id == 11), Pillar = _context.Pillars.Local.First(x => x.Id == 1), Group = _context.Groups.Local.First(x => x.Id == 41), Order = 40, YtdFormula = Enums.YtdFormula.Sum, IsEconomic = true, FormatInput = FormatInput.Numeric, IsActive = true, CreatedDate = DateTime.FromOADate(41988.8212714931), UpdatedDate = DateTime.Now, Method = _context.Methods.Local.First(x => x.Id == 3), Level = _context.Levels.Local.First(x => x.Id == 3), RoleGroup = _context.RoleGroups.Local.First(x => x.Id == 10), Type = _context.Types.Local.First(x => x.Id == 1) };

            _context.Kpis.Add(kpi1);
            _context.Kpis.Add(kpi2);
            _context.Kpis.Add(kpi3);
            _context.Kpis.Add(kpi4);
            _context.Kpis.Add(kpi5);
            _context.Kpis.Add(kpi6);
            _context.Kpis.Add(kpi7);
            _context.Kpis.Add(kpi8);
            _context.Kpis.Add(kpi9);
            _context.Kpis.Add(kpi10);
            _context.Kpis.Add(kpi11);
            _context.Kpis.Add(kpi12);
            _context.Kpis.Add(kpi13);
            _context.Kpis.Add(kpi14);
            _context.Kpis.Add(kpi15);
            _context.Kpis.Add(kpi16);
            _context.Kpis.Add(kpi17);
            _context.Kpis.Add(kpi18);
            _context.Kpis.Add(kpi19);
            _context.Kpis.Add(kpi20);
            _context.Kpis.Add(kpi21);
            _context.Kpis.Add(kpi22);
            _context.Kpis.Add(kpi23);
            _context.Kpis.Add(kpi24);
            _context.Kpis.Add(kpi25);
            _context.Kpis.Add(kpi26);
            _context.Kpis.Add(kpi27);
            _context.Kpis.Add(kpi28);
            _context.Kpis.Add(kpi29);
            _context.Kpis.Add(kpi30);
            _context.Kpis.Add(kpi31);
            _context.Kpis.Add(kpi32);
            _context.Kpis.Add(kpi33);
            _context.Kpis.Add(kpi34);
            _context.Kpis.Add(kpi35);
        }
Ejemplo n.º 8
0
        public DeleteKpiResponse Delete(int id)
        {
            var response = new DeleteKpiResponse();
            try
            {
                var kpi = new Kpi { Id = id };
                DataContext.Kpis.Attach(kpi);
                DataContext.Entry(kpi).State = EntityState.Deleted;
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "KPI item has been deleted successfully";
            }
            catch (DbUpdateException dbUpdateException)
            {
                response.Message = dbUpdateException.Message;
            }

            return response;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        public SaveKpiTransformationResponse Save(SaveKpiTransformationRequest request)
        {
            try
            {
                if (request.Id == 0)
                {
                    var kpiTransformation = new KpiTransformation { Name = request.Name, PeriodeType = request.PeriodeType };
                    foreach (var roleId in request.RoleGroupIds.Distinct().ToArray())
                    {
                        var role = new RoleGroup { Id = roleId };
                        DataContext.RoleGroups.Attach(role);
                        kpiTransformation.RoleGroups.Add(role);
                    }
                    foreach (var kpiId in request.KpiIds.Distinct().ToArray())
                    {
                        var kpi = new Kpi { Id = kpiId };
                        DataContext.Kpis.Attach(kpi);
                        kpiTransformation.Kpis.Add(kpi);
                    }
                    DataContext.KpiTransformations.Add(kpiTransformation);
                    DataContext.SaveChanges();
                }
                else
                {
                    var kpiTransformation = DataContext.KpiTransformations.Include(x => x.RoleGroups).Include(x => x.Kpis).Single(x => x.Id == request.Id);
                    kpiTransformation.Name = request.Name;
                    kpiTransformation.PeriodeType = request.PeriodeType;
                    foreach (var role in kpiTransformation.RoleGroups.ToList())
                    {
                        kpiTransformation.RoleGroups.Remove(role);
                    }
                    foreach (var kpi in kpiTransformation.Kpis.ToList())
                    {
                        kpiTransformation.Kpis.Remove(kpi);
                    }
                    foreach (var roleId in request.RoleGroupIds.Distinct().ToArray())
                    {
                        var role = DataContext.RoleGroups.Local.FirstOrDefault(x => x.Id == roleId);
                        if (role == null)
                        {
                            role = new RoleGroup { Id = roleId };
                            DataContext.RoleGroups.Attach(role);

                        }
                        kpiTransformation.RoleGroups.Add(role);

                    }
                    foreach (var kpiId in request.KpiIds.Distinct().ToArray())
                    {
                        var kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpiId);
                        if (kpi == null)
                        {
                            kpi = new Kpi { Id = kpiId };
                            DataContext.Kpis.Attach(kpi);
                        }
                        kpiTransformation.Kpis.Add(kpi);
                    }
                    DataContext.SaveChanges();
                }
                return new SaveKpiTransformationResponse
                {
                    IsSuccess = true,
                    Message = "You have been successfully updated kpi transformation"
                };
            }
            catch(Exception e) {
                return new SaveKpiTransformationResponse
                {
                    IsSuccess = false,
                    Message = e.Message
                };
            }
        }
Ejemplo n.º 11
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.º 12
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.º 13
0
        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;
        }
Ejemplo n.º 14
0
        public BaseResponse KpiEconomicInput(KpiEconomicInputRequest request)
        {
            try
            {
                var scenario = DataContext.Scenarios.FirstOrDefault(x => x.IsActive && x.IsDashboard);
                if (scenario == null)
                {
                    return new BaseResponse
                    {
                        IsSuccess = false,
                        Message = "An error occured, please contact adminstrator for further information"
                    };
                }

                //yearly
                var year = request.Start.Year;
                var yarlyEconomic = DataContext.KeyOperationDatas.FirstOrDefault(x => x.Kpi.Id == request.KpiId && x.PeriodeType == PeriodeType.Yearly
                    && x.Periode.Year == year && x.Scenario.Id == scenario.Id);
                var kpi = new Kpi { Id = request.KpiId };
                DataContext.Kpis.Attach(kpi);
                if (yarlyEconomic != null)
                {
                    yarlyEconomic.Value = request.Value;
                }
                else
                {
                    var newYearlyEconomic = new KeyOperationData
                    {
                        Value = request.Value,
                        PeriodeType = PeriodeType.Yearly,
                        Periode = request.Start,
                        Kpi = kpi,
                        Scenario = scenario
                    };
                    DataContext.KeyOperationDatas.Add(newYearlyEconomic);
                }

                //monthly
                //var monthlyEconomics = DataContext.KeyOperationDatas.Where(x => x.Kpi.Id == request.KpiId
                //    && x.PeriodeType == PeriodeType.Monthly
                //    && x.Periode >= request.Start && x.Periode <= request.End
                //    && x.Scenario.Id == scenario.Id).ToList();

                //for (var i = request.Start.Month; i <= request.End.Month; i++)
                //{
                //    var monthlyEconomic = monthlyEconomics.FirstOrDefault(x => x.Periode.Month == i);
                //    if (monthlyEconomic != null)
                //    {
                //        monthlyEconomic.Value = request.Value;
                //    }
                //    else
                //    {
                //        var newMonthlyEconomic = new KeyOperationData
                //        {
                //            Periode = new DateTime(year, i, 1),
                //            PeriodeType = PeriodeType.Monthly,
                //            Value = request.Value,
                //            Kpi = kpi,
                //            Scenario = scenario
                //        };
                //        DataContext.KeyOperationDatas.Add(newMonthlyEconomic);
                //    }
                //}

                DataContext.SaveChanges();
                return new BaseResponse
                {
                    IsSuccess = true,
                    Message = "Kpi Valu has been saved successfully"
                };
            }
            catch
            {
                return new BaseResponse
                {
                    IsSuccess = false,
                    Message = "An error occured, please contact adminstrator for further information"
                };
            }
        }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
        public BaseResponse KpiTargetInput(KpiTargetInputRequest request)
        {
            try
            {
                //yearly
                var year = request.Start.Year;
                var yearlyTarget = DataContext.KpiTargets.FirstOrDefault(x => x.Kpi.Id == request.KpiId && x.PeriodeType == PeriodeType.Yearly
                    && x.Periode.Year == year);
                var kpi = new Kpi { Id = request.KpiId };
                DataContext.Kpis.Attach(kpi);
                if (yearlyTarget != null)
                {
                    yearlyTarget.Value = request.Value;
                }
                else
                {
                    var newYearlyTarget = new KpiTarget
                    {
                        Value = request.Value,
                        PeriodeType = PeriodeType.Yearly,
                        Periode = new DateTime(request.Start.Year, 1, 1),
                        Kpi = kpi
                    };
                    DataContext.KpiTargets.Add(newYearlyTarget);
                }

                //monthly
                //var monthlyTargets = DataContext.KpiTargets.Where(x => x.Kpi.Id == request.KpiId
                //    && x.PeriodeType == PeriodeType.Monthly
                //    && x.Periode >= request.Start && x.Periode <= request.End).ToList();

                //for (var i = request.Start.Month; i <= request.End.Month; i++)
                //{
                //    var monthlyTarget = monthlyTargets.FirstOrDefault(x => x.Periode.Month == i);
                //    if (monthlyTarget != null)
                //    {
                //        monthlyTarget.Value = request.Value;
                //    }
                //    else
                //    {
                //        var newMonthlyTarget = new KpiTarget
                //        {
                //            Periode = new DateTime(year, i, 1),
                //            PeriodeType = PeriodeType.Monthly,
                //            Value = request.Value,
                //            Kpi = kpi
                //        };
                //        DataContext.KpiTargets.Add(newMonthlyTarget);
                //    }
                //}

                DataContext.SaveChanges();
                return new BaseResponse
                {
                    IsSuccess = true,
                    Message = "Kpi Valu has been saved successfully"
                };
            }
            catch
            {
                return new BaseResponse
                {
                    IsSuccess = false,
                    Message = "An error occured, please contact adminstrator for further information"
                };
            }
        }
Ejemplo n.º 17
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"
                };
            }
        }