예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
0
        private BaseResponse SaveDafwc(SaveLayoutItemRequest request)
        {
            var response = new GetDerLayoutResponse();
            try
            {
                if (request.Id > 0)
                {

                }
                else
                {
                    var derLayoutItem = new DerLayoutItem();
                    var derLayout = new DerLayout { Id = request.DerLayoutId };
                    DataContext.DerLayouts.Attach(derLayout);
                    derLayoutItem.DerLayout = derLayout;
                    derLayoutItem.Column = request.Column;
                    derLayoutItem.Row = request.Row;
                    derLayoutItem.Type = request.Type;
                    DataContext.DerLayoutItems.Add(derLayoutItem);
                }

                DataContext.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
예제 #4
0
        private BaseResponse SaveHighlight(SaveLayoutItemRequest request)
        {
            var response = new GetDerLayoutResponse();
            try
            {
                var derLayoutItem = new DerLayoutItem();
                var derLayout = new DerLayout { Id = request.DerLayoutId };
                DataContext.DerLayouts.Attach(derLayout);
                derLayoutItem.DerLayout = derLayout;
                derLayoutItem.Column = request.Column;
                derLayoutItem.Row = request.Row;
                derLayoutItem.Type = request.Type;
                var derHiglight = new DerHighlight();
                var selectOption = new SelectOption { Id = request.Highlight.SelectOptionId };
                DataContext.SelectOptions.Attach(selectOption);
                derHiglight.SelectOption = selectOption;
                derLayoutItem.Highlight = derHiglight;
                DataContext.DerHighlights.Add(derHiglight);
                DataContext.DerLayoutItems.Add(derLayoutItem);

                DataContext.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
예제 #5
0
        public SaveOriginalDataResponse SaveOriginalData(SaveOriginalDataRequest request)
        {
            var response = new SaveOriginalDataResponse();
            try
            {
                foreach (var datum in request.OriginalData)
                {
                    var layoutItem = new DerLayoutItem { Id = datum.LayoutItemId };
                    if (DataContext.DerLayoutItems.Local.FirstOrDefault(x => x.Id == layoutItem.Id) == null)
                    {
                        DataContext.DerLayoutItems.Attach(layoutItem);
                    }
                    else
                    {
                        layoutItem = DataContext.DerLayoutItems.Local.FirstOrDefault(x => x.Id == layoutItem.Id);
                    }

                    switch (datum.Type)
                    {
                        case "job-pmts":
                            {
                                if (datum.IsKpiAchievement)
                                {
                                    SaveOriginalDataRequest.OriginalDataRequest datum1 = datum;
                                    var kpi = DataContext.Kpis.Single(x => x.Id == datum1.KpiId);
                                    var kpiAchievements = DataContext.KpiAchievements
                                        .Include(x => x.Kpi)
                                        .Where(x => x.Kpi.Id == datum1.KpiId && ((x.Periode.Month == datum1.Periode.Month &&
                                                                             x.Periode.Year == datum1.Periode.Year) || x.Periode.Year == datum1.Periode.Year)).ToList();
                                    var kpiAchievementYearly =
                                        DataContext.KpiAchievements.Where(
                                            x => x.Periode.Year == 2016 && x.PeriodeType == PeriodeType.Yearly).ToList();
                                    var dailyActual = kpiAchievements.FirstOrDefault(x => x.PeriodeType == PeriodeType.Daily
                                        && x.Periode.Day == datum1.Periode.Day);

                                    if (!string.IsNullOrEmpty(datum1.Data))
                                    {
                                        double val;
                                        bool isParsed = double.TryParse(datum1.Data, out val);
                                        if (isParsed)
                                        {
                                            if (dailyActual != null)
                                            {
                                                dailyActual.Value = val;
                                            }
                                            else
                                            {
                                                dailyActual = new KpiAchievement
                                                {
                                                    Kpi = DataContext.Kpis.Single(x => x.Id == datum.KpiId),
                                                    Value = val
                                                };
                                                DataContext.KpiAchievements.Add(dailyActual);
                                            }
                                        }
                                    }

                                    var monthly = kpiAchievements.Where(x => x.PeriodeType == PeriodeType.Daily &&
                                                                              (x.Periode.Month == datum1.Periode.Month &&
                                                                               x.Periode.Year == datum1.Periode.Year))
                                                                  .AsQueryable();
                                    double? achievementMtd = null;
                                    if (kpi.YtdFormula == YtdFormula.Sum)
                                    {
                                        achievementMtd = monthly.Sum(x => x.Value);
                                    }
                                    else if (kpi.YtdFormula == YtdFormula.Average)
                                    {
                                        achievementMtd = monthly.Average(x => x.Value);
                                    }

                                    var monthlyActual = monthly.FirstOrDefault();

                                    if (monthlyActual != null)
                                    {
                                        monthlyActual.Value = achievementMtd;
                                    }

                                    var yearly = kpiAchievements.Where(x => x.PeriodeType == PeriodeType.Monthly && x.Periode.Year == datum1.Periode.Year)
                                                                  .AsQueryable();
                                    double? achievementYtd = null;
                                    if (kpi.YtdFormula == YtdFormula.Sum)
                                    {
                                        achievementYtd = yearly.Sum(x => x.Value);
                                    }
                                    else if (kpi.YtdFormula == YtdFormula.Average)
                                    {
                                        achievementYtd = yearly.Average(x => x.Value);
                                    }

                                    var yearlyActual = yearly.FirstOrDefault();
                                    if (yearlyActual != null)
                                    {
                                        yearlyActual.Value = achievementYtd;
                                    }
                                }
                                break;
                            }
                        default:
                            {
                                if (datum.Id > 0)
                                {
                                    var originalData = datum.MapTo<DerOriginalData>();
                                    originalData.LayoutItem = layoutItem;
                                    DataContext.DerOriginalDatas.Attach(originalData);
                                    DataContext.Entry(originalData).State = EntityState.Modified;
                                }
                                else
                                {
                                    var originalData = datum.MapTo<DerOriginalData>();
                                    originalData.LayoutItem = layoutItem;
                                    DataContext.DerOriginalDatas.Add(originalData);
                                }
                                break;
                            }
                    }
                }

                //DataContext.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
예제 #6
0
        private BaseResponse SaveTank(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>();
                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);

                DataContext.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
예제 #7
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;
        }
예제 #8
0
파일: DerService.cs 프로젝트: fazar/Pear
        private BaseResponse SaveUser(SaveLayoutItemRequest request)
        {
            var response = new GetDerLayoutResponse();
            try
            {
                var derLayoutItem = new DerLayoutItem();
                var derLayout = new DerLayout { Id = request.DerLayoutId };
                DataContext.DerLayouts.Attach(derLayout);
                derLayoutItem.DerLayout = derLayout;
                derLayoutItem.Column = request.Column;
                derLayoutItem.Row = request.Row;
                derLayoutItem.Type = request.Type;
                derLayoutItem.SignedBy = DataContext.Users.Single(x => x.Id == request.SignedBy);

                DataContext.DerLayoutItems.Add(derLayoutItem);

                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "Changes has been saved";
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
예제 #9
0
파일: DerService.cs 프로젝트: fazar/Pear
        private BaseResponse SaveSpeedometer(SaveLayoutItemRequest request)
        {
            var response = new BaseResponse();
            try
            {
                var derLayoutItem = new DerLayoutItem();
                var derLayout = new DerLayout { Id = request.DerLayoutId };
                DataContext.DerLayouts.Attach(derLayout);
                derLayoutItem.DerLayout = derLayout;
                derLayoutItem.Column = request.Column;
                derLayoutItem.Row = request.Row;
                derLayoutItem.Type = request.Type;
                var derArtifact = new DerArtifact();
                derArtifact.GraphicType = request.Type;

                var plots = request.Artifact.Speedometer.PlotBands.Select(x => new DerArtifactPlot
                {
                    Color = x.Color,
                    From = x.From,
                    To = x.To
                }).ToList();
                derArtifact.Plots = plots;
                derArtifact.CustomSerie = DataContext.Kpis.FirstOrDefault(y => y.Id == request.Artifact.Speedometer.Series.KpiId);
                if (request.Artifact.Speedometer.LabelSeries != null)
                {
                    var labelSeries = new DerArtifactSerie
                    {
                        Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == request.Artifact.Speedometer.LabelSeries.KpiId),
                        Label = "ton/d",
                        Color = "#000"
                    };
                    derArtifact.Series = new List<DerArtifactSerie>();
                    derArtifact.Series.Add(labelSeries);
                }
                DataContext.DerArtifacts.Add(derArtifact);
                derLayoutItem.Artifact = derArtifact;
                DataContext.DerLayoutItems.Add(derLayoutItem);

                DataContext.SaveChanges();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }