Esempio n. 1
0
        private void PrePopulateReportedPerformanceMeasures(Project project, ICollection <PerformanceMeasureExpected> expectedPerformanceMeasures,
                                                            List <PerformanceMeasureActualSimple> performanceMeasureActualSimples)
        {
            var sortedExpectedPerformanceMeasures = expectedPerformanceMeasures.OrderBy(pam => pam.PerformanceMeasure.PerformanceMeasureSortOrder)
                                                    .ThenBy(x => x.PerformanceMeasure.GetDisplayName()).ToList();
            var yearRange        = project.GetProjectUpdateImplementationStartToCompletionYearRange();
            var reportingPeriods = HttpRequestStorage.DatabaseEntities.PerformanceMeasureReportingPeriods.ToList();
            var performanceMeasureActualIDToUse = -1;

            foreach (var calendarYear in yearRange)
            {
                var reportingPeriod =
                    reportingPeriods.SingleOrDefault(x => x.PerformanceMeasureReportingPeriodCalendarYear == calendarYear);
                if (reportingPeriod == null)
                {
                    var newPerformanceMeasureReportingPeriod =
                        new PerformanceMeasureReportingPeriod(calendarYear, calendarYear.ToString());
                    HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureReportingPeriods.Add(
                        newPerformanceMeasureReportingPeriod);
                    HttpRequestStorage.DatabaseEntities.SaveChanges(CurrentFirmaSession);
                }

                foreach (var sortedExpectedPerformanceMeasure in sortedExpectedPerformanceMeasures)
                {
                    var performanceMeasureActual = new PerformanceMeasureActualSimple(sortedExpectedPerformanceMeasure,
                                                                                      calendarYear, performanceMeasureActualIDToUse);
                    performanceMeasureActualSimples.Add(performanceMeasureActual);
                    performanceMeasureActualIDToUse--;
                }
            }
        }
        private void UpdateModelImpl(List <ProjectFirmaModels.Models.PerformanceMeasureActual> currentPerformanceMeasureActuals,
                                     IList <ProjectFirmaModels.Models.PerformanceMeasureActual> allPerformanceMeasureActuals,

                                     IList <PerformanceMeasureActualSubcategoryOption> allPerformanceMeasureActualSubcategoryOptions,
                                     IList <PerformanceMeasureReportingPeriod> allPerformanceMeasureReportingPeriods)
        {
            // Remove all existing associations
            currentPerformanceMeasureActuals.ForEach(pmav =>
            {
                pmav.PerformanceMeasureActualSubcategoryOptions.ToList().ForEach(pmavso => allPerformanceMeasureActualSubcategoryOptions.Remove(pmavso));
                allPerformanceMeasureActuals.Remove(pmav);
            });
            currentPerformanceMeasureActuals.Clear();

            if (PerformanceMeasureActuals != null)
            {
                var performanceMeasureReportingPeriodsFromDatabase = HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureReportingPeriods.Local;
                // Completely rebuild the list
                foreach (var performanceMeasureActualSimple in PerformanceMeasureActuals)
                {
                    var performanceMeasureReportingPeriod = allPerformanceMeasureReportingPeriods.SingleOrDefault(x => x.PerformanceMeasureReportingPeriodCalendarYear == performanceMeasureActualSimple.CalendarYear);
                    if (performanceMeasureReportingPeriod == null)
                    {
                        Check.EnsureNotNull(performanceMeasureActualSimple.PerformanceMeasureID, "We need to have a performance measure.");
                        performanceMeasureReportingPeriod = new PerformanceMeasureReportingPeriod((int)performanceMeasureActualSimple.PerformanceMeasureID, performanceMeasureActualSimple.CalendarYear, performanceMeasureActualSimple.CalendarYear.ToString());
                        performanceMeasureReportingPeriodsFromDatabase.Add(performanceMeasureReportingPeriod);
                        HttpRequestStorage.DatabaseEntities.SaveChanges();
                    }
                    var performanceMeasureActual = new ProjectFirmaModels.Models.PerformanceMeasureActual(performanceMeasureActualSimple.ProjectID.Value, performanceMeasureActualSimple.PerformanceMeasureID.Value, performanceMeasureActualSimple.ActualValue.Value, performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodID);
                    allPerformanceMeasureActuals.Add(performanceMeasureActual);
                    if (performanceMeasureActualSimple.PerformanceMeasureActualSubcategoryOptions != null)
                    {
                        performanceMeasureActualSimple.PerformanceMeasureActualSubcategoryOptions.ForEach(
                            y =>
                            allPerformanceMeasureActualSubcategoryOptions.Add(new PerformanceMeasureActualSubcategoryOption(
                                                                                  performanceMeasureActual.PerformanceMeasureActualID,
                                                                                  y.PerformanceMeasureSubcategoryOptionID.Value,
                                                                                  y.PerformanceMeasureID,
                                                                                  y.PerformanceMeasureSubcategoryID)));
                    }
                }
            }
        }
Esempio n. 3
0
            public static PerformanceMeasureReportingPeriod Create(PerformanceMeasure performanceMeasure, int calendarYear)
            {
                var performanceMeasureReportingPeriod = new PerformanceMeasureReportingPeriod(calendarYear, calendarYear.ToString());

                return(performanceMeasureReportingPeriod);
            }
Esempio n. 4
0
            public static PerformanceMeasureReportingPeriod Create(PerformanceMeasure performanceMeasure)
            {
                var performanceMeasureReportingPeriod = new PerformanceMeasureReportingPeriod(DateTime.Now.Year, DateTime.Now.Year.ToString());

                return(performanceMeasureReportingPeriod);
            }
        public void UpdateModel(ProjectUpdateBatch projectUpdateBatch)
        {
            var allPerformanceMeasureReportingPeriods   = HttpRequestStorage.DatabaseEntities.PerformanceMeasureReportingPeriods.ToList();
            var performanceMeasureReportingPeriodsToAdd = new List <PerformanceMeasureReportingPeriod>();

            if (PerformanceMeasureActualUpdates != null)
            {
                foreach (var performanceMeasureActualUpdateSimple in PerformanceMeasureActualUpdates)
                {
                    var performanceMeasureReportingPeriod = allPerformanceMeasureReportingPeriods.SingleOrDefault(x =>
                                                                                                                  x.PerformanceMeasureReportingPeriodCalendarYear ==
                                                                                                                  performanceMeasureActualUpdateSimple.CalendarYear);

                    if (performanceMeasureReportingPeriod == null)
                    {
                        Check.EnsureNotNull(performanceMeasureActualUpdateSimple.PerformanceMeasureID, "We need to have a performance measure.");
                        performanceMeasureReportingPeriod = new PerformanceMeasureReportingPeriod((int)performanceMeasureActualUpdateSimple.PerformanceMeasureID, performanceMeasureActualUpdateSimple.CalendarYear, performanceMeasureActualUpdateSimple.CalendarYear.ToString());
                        performanceMeasureReportingPeriodsToAdd.Add(performanceMeasureReportingPeriod);
                    }
                }
            }

            HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureReportingPeriods.AddRange(performanceMeasureReportingPeriodsToAdd);
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);


            var allPerformanceMeasureReportingPeriodsReloaded = HttpRequestStorage.DatabaseEntities.PerformanceMeasureReportingPeriods.ToList();
            var performanceMeasureActualUpdatesUpdated        = new List <PerformanceMeasureActualUpdate>();

            if (PerformanceMeasureActualUpdates != null)
            {
                foreach (var performanceMeasureActualUpdateSimple in PerformanceMeasureActualUpdates)
                {
                    var performanceMeasureReportingPeriod = allPerformanceMeasureReportingPeriodsReloaded.Single(x =>
                                                                                                                 x.PerformanceMeasureReportingPeriodCalendarYear ==
                                                                                                                 performanceMeasureActualUpdateSimple.CalendarYear);
                    var performanceMeasureActual = new PerformanceMeasureActualUpdate(
                        performanceMeasureActualUpdateSimple.PerformanceMeasureActualUpdateID,
                        performanceMeasureActualUpdateSimple.ProjectUpdateBatchID,
                        performanceMeasureActualUpdateSimple.PerformanceMeasureID,
                        performanceMeasureActualUpdateSimple.ActualValue,
                        performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodID);
                    if (performanceMeasureActualUpdateSimple.PerformanceMeasureActualSubcategoryOptionUpdates != null)
                    {
                        AddPerformanceMeasureActualSubcategoryOptionUpdates(performanceMeasureActual, performanceMeasureActualUpdateSimple);
                    }

                    performanceMeasureActualUpdatesUpdated.Add(performanceMeasureActual);
                }
            }



            var listOfPerformanceMeasureActualUpdateIDsToMergeWith = performanceMeasureActualUpdatesUpdated
                                                                     .Select(x => x.PerformanceMeasureActualUpdateID).ToList();

            var updateList = HttpRequestStorage.DatabaseEntities.PerformanceMeasureActualUpdates.Where(x =>
                                                                                                       listOfPerformanceMeasureActualUpdateIDsToMergeWith.Contains(x.PerformanceMeasureActualUpdateID)).ToList();
            var updateListOfIds = updateList.Select(x => x.PerformanceMeasureActualUpdateID).ToList();

            var deleteList = projectUpdateBatch.PerformanceMeasureActualUpdates.Where(x =>
                                                                                      !listOfPerformanceMeasureActualUpdateIDsToMergeWith.Contains(x.PerformanceMeasureActualUpdateID))
                             .ToList();
            var deleteListOfIds = deleteList.Select(x => x.PerformanceMeasureActualUpdateID).ToList();

            updateListOfIds.AddRange(deleteListOfIds);

            var addList = performanceMeasureActualUpdatesUpdated
                          .Where(x => !ModelObjectHelpers.IsRealPrimaryKeyValue(x.PerformanceMeasureActualUpdateID) || !updateListOfIds.Contains(x.PerformanceMeasureActualUpdateID)).ToList();

            foreach (var performanceMeasureActualUpdate in updateList)
            {
                var update = performanceMeasureActualUpdatesUpdated.Single(x => x.PerformanceMeasureActualUpdateID == performanceMeasureActualUpdate.PerformanceMeasureActualUpdateID);
                performanceMeasureActualUpdate.PerformanceMeasureReportingPeriodID = update.PerformanceMeasureReportingPeriodID;
                performanceMeasureActualUpdate.ActualValue = update.ActualValue;
            }
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);

            deleteList.ForEach(x => x.DeleteFull(HttpRequestStorage.DatabaseEntities));
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);


            HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureActualUpdates.AddRange(addList);
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);



            var listOfOptionsToAdd    = performanceMeasureActualUpdatesUpdated.SelectMany(x => x.PerformanceMeasureActualSubcategoryOptionUpdates).ToList();
            var listOfOptionsToDelete = projectUpdateBatch.PerformanceMeasureActualUpdates
                                        .SelectMany(x => x.PerformanceMeasureActualSubcategoryOptionUpdates).ToList();

            listOfOptionsToDelete.ForEach(x => x.DeleteFull(HttpRequestStorage.DatabaseEntities));
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);
            HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureActualSubcategoryOptionUpdates.AddRange(listOfOptionsToAdd);
            HttpRequestStorage.DatabaseEntities.SaveChanges(IsolationLevel.ReadUncommitted);

            var databaseEntities = HttpRequestStorage.DatabaseEntities;
            var currentProjectExemptYearUpdates = projectUpdateBatch.GetPerformanceMeasuresExemptReportingYears();

            databaseEntities.ProjectExemptReportingYearUpdates.Load();
            var allProjectExemptYearUpdates = databaseEntities.AllProjectExemptReportingYearUpdates.Local;
            var projectExemptReportingYears = new List <ProjectExemptReportingYearUpdate>();

            if (ProjectExemptReportingYearUpdates != null)
            {
                // Completely rebuild the list
                projectExemptReportingYears =
                    ProjectExemptReportingYearUpdates.Where(x => x.IsExempt)
                    .Select(x => new ProjectExemptReportingYearUpdate(x.ProjectExemptReportingYearUpdateID, x.ProjectUpdateBatchID, x.CalendarYear, ProjectExemptReportingType.PerformanceMeasures.ProjectExemptReportingTypeID))
                    .ToList();
            }
            currentProjectExemptYearUpdates.Merge(projectExemptReportingYears,
                                                  allProjectExemptYearUpdates,
                                                  (x, y) => x.ProjectUpdateBatchID == y.ProjectUpdateBatchID && x.CalendarYear == y.CalendarYear && x.ProjectExemptReportingTypeID == y.ProjectExemptReportingTypeID, HttpRequestStorage.DatabaseEntities);
            projectUpdateBatch.PerformanceMeasureActualYearsExemptionExplanation = Explanation;
        }
        public void UpdateModel(List <ProjectFirmaModels.Models.PerformanceMeasureActual> currentPerformanceMeasureActuals,
                                IList <ProjectFirmaModels.Models.PerformanceMeasureActual> allPerformanceMeasureActuals,
                                IList <PerformanceMeasureActualSubcategoryOption> allPerformanceMeasureActualSubcategoryOptions,
                                ProjectFirmaModels.Models.Project project,
                                IList <PerformanceMeasureReportingPeriod> allPerformanceMeasureReportingPeriods)
        {
            var currentPerformanceMeasureActualSubcategoryOptions =
                currentPerformanceMeasureActuals.SelectMany(x => x.PerformanceMeasureActualSubcategoryOptions).ToList();
            var performanceMeasureActualsUpdated = new List <ProjectFirmaModels.Models.PerformanceMeasureActual>();

            if (PerformanceMeasureActualSimples != null)
            {
                // Renumber negative indexes for PerformanceMeasureActuals
                RenumberPerformanceMeasureActuals(PerformanceMeasureActualSimples);

                var performanceMeasureReportingPeriodsFromDatabase = HttpRequestStorage.DatabaseEntities.AllPerformanceMeasureReportingPeriods.Local;
                // Completely rebuild the list
                performanceMeasureActualsUpdated = PerformanceMeasureActualSimples.Select(x =>
                {
                    var performanceMeasureReportingPeriod = allPerformanceMeasureReportingPeriods.SingleOrDefault(y => y.PerformanceMeasureReportingPeriodCalendarYear == x.CalendarYear);
                    if (performanceMeasureReportingPeriod == null)
                    {
                        Check.EnsureNotNull(x.PerformanceMeasureID, "We need to have a performance measure.");
                        performanceMeasureReportingPeriod = new PerformanceMeasureReportingPeriod((int)x.PerformanceMeasureID, x.CalendarYear, x.CalendarYear.ToString());
                        performanceMeasureReportingPeriodsFromDatabase.Add(performanceMeasureReportingPeriod);
                        HttpRequestStorage.DatabaseEntities.SaveChanges();
                    }

                    var performanceMeasureActual = new ProjectFirmaModels.Models.PerformanceMeasureActual(x.PerformanceMeasureActualID.GetValueOrDefault(),
                                                                                                          x.ProjectID.GetValueOrDefault(),
                                                                                                          x.PerformanceMeasureID.GetValueOrDefault(),
                                                                                                          x.ActualValue.GetValueOrDefault(),
                                                                                                          performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodID);
                    if (x.PerformanceMeasureActualSubcategoryOptions != null)
                    {
                        performanceMeasureActual.PerformanceMeasureActualSubcategoryOptions =
                            x.PerformanceMeasureActualSubcategoryOptions.Where(pmavsou => ModelObjectHelpers.IsRealPrimaryKeyValue(pmavsou.PerformanceMeasureSubcategoryOptionID))
                            .Select(
                                y =>
                                new PerformanceMeasureActualSubcategoryOption(performanceMeasureActual.PerformanceMeasureActualID,
                                                                              y.PerformanceMeasureSubcategoryOptionID.GetValueOrDefault(),
                                                                              y.PerformanceMeasureID,
                                                                              y.PerformanceMeasureSubcategoryID))
                            .ToList();
                    }
                    return(performanceMeasureActual);
                }).ToList();
            }

            var databaseEntities = HttpRequestStorage.DatabaseEntities;

            currentPerformanceMeasureActuals.Merge(performanceMeasureActualsUpdated,
                                                   allPerformanceMeasureActuals,
                                                   (x, y) => x.PerformanceMeasureActualID == y.PerformanceMeasureActualID,
                                                   (x, y) =>
            {
                x.PerformanceMeasureReportingPeriodID = y.PerformanceMeasureReportingPeriodID;
                x.ActualValue = y.ActualValue;
            }, databaseEntities);

            currentPerformanceMeasureActualSubcategoryOptions.Merge(
                performanceMeasureActualsUpdated.SelectMany(x => x.PerformanceMeasureActualSubcategoryOptions).ToList(),
                allPerformanceMeasureActualSubcategoryOptions,
                (x, y) => x.PerformanceMeasureActualID == y.PerformanceMeasureActualID && x.PerformanceMeasureSubcategoryID == y.PerformanceMeasureSubcategoryID && x.PerformanceMeasureID == y.PerformanceMeasureID,
                (x, y) => x.PerformanceMeasureSubcategoryOptionID = y.PerformanceMeasureSubcategoryOptionID, databaseEntities);

            var currentProjectExemptYears = project.GetPerformanceMeasuresExemptReportingYears();

            databaseEntities.ProjectExemptReportingYears.Load();
            var allProjectExemptYears       = databaseEntities.AllProjectExemptReportingYears.Local;
            var projectExemptReportingYears = new List <ProjectExemptReportingYear>();

            if (ProjectExemptReportingYearSimples != null)
            {
                // Completely rebuild the list
                projectExemptReportingYears =
                    ProjectExemptReportingYearSimples.Where(x => x.IsExempt)
                    .Select(x => new ProjectExemptReportingYear(x.ProjectExemptReportingYearID, x.ProjectID, x.CalendarYear, ProjectExemptReportingType.PerformanceMeasures.ProjectExemptReportingTypeID))
                    .ToList();
            }
            currentProjectExemptYears.Merge(projectExemptReportingYears,
                                            allProjectExemptYears,
                                            (x, y) => x.ProjectID == y.ProjectID && x.CalendarYear == y.CalendarYear && x.ProjectExemptReportingTypeID == y.ProjectExemptReportingTypeID, HttpRequestStorage.DatabaseEntities);
            project.PerformanceMeasureActualYearsExemptionExplanation = Explanation;
            if (project.ProjectApprovalStatus == ProjectApprovalStatus.PendingApproval)
            {
                project.ReportedAccomplishmentsComment = Comments;
            }
        }
            public static PerformanceMeasureActual Create(int performanceMeasureActualID, Project project, PerformanceMeasure performanceMeasure, PerformanceMeasureReportingPeriod performanceMeasureReportingPeriod, double actualValue)
            {
                var performanceMeasureActual = PerformanceMeasureActual.CreateNewBlank(project, performanceMeasure, performanceMeasureReportingPeriod);

                performanceMeasureActual.PerformanceMeasureActualID = performanceMeasureActualID;
                performanceMeasureActual.ActualValue = actualValue;
                return(performanceMeasureActual);
            }
            public static PerformanceMeasureActual Create(Project project, PerformanceMeasure performanceMeasure, PerformanceMeasureReportingPeriod performanceMeasureReportingPeriod)
            {
                var performanceMeasureActual = PerformanceMeasureActual.CreateNewBlank(project, performanceMeasure, performanceMeasureReportingPeriod);

                return(performanceMeasureActual);
            }
        public void UpdateModel(ProjectFirmaModels.Models.GeospatialArea geospatialArea,
                                ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure,
                                ICollection <PerformanceMeasureReportingPeriod> allPerformanceMeasureReportingPeriods,
                                ICollection <GeospatialAreaPerformanceMeasureNoTarget> allGeospatialAreaPerformanceMeasureNoTargets,
                                ICollection <GeospatialAreaPerformanceMeasureFixedTarget> allGeospatialAreaPerformanceMeasureFixedTargets,
                                ICollection <GeospatialAreaPerformanceMeasureReportingPeriodTarget> allGeospatialAreaPerformanceMeasureReportingPeriodTargets)
        {
            var performanceMeasureTargetValueTypeEnum = PerformanceMeasureTargetValueType.AllLookupDictionary[PerformanceMeasureTargetValueTypeID].ToEnum;

            DeleteOtherGeospatialAreaPerformanceMeasureTargetValueTypes(performanceMeasure, geospatialArea, performanceMeasureTargetValueTypeEnum);

            switch (performanceMeasureTargetValueTypeEnum)
            {
            case PerformanceMeasureTargetValueTypeEnum.NoTarget:
                // Make a "no target" object.
                // ReSharper disable once UnusedVariable
                var noTarget = GeospatialAreaPerformanceMeasureNoTargetModelExtensions.GetOrCreateGeospatialAreaPerformanceMeasureNoTarget(performanceMeasure, geospatialArea);
                break;

            case PerformanceMeasureTargetValueTypeEnum.FixedTarget:
                var fixedTarget = performanceMeasure.GetOrCreateGeospatialAreaPerformanceMeasureFixedTarget(geospatialArea, FixedTargetValue.Value);
                fixedTarget.GeospatialAreaPerformanceMeasureTargetValueLabel = FixedTargetValueLabel;
                fixedTarget.GeospatialAreaPerformanceMeasureTargetValue      = FixedTargetValue.Value;
                break;

            case PerformanceMeasureTargetValueTypeEnum.TargetPerYear:
                var geospatialAreaPerformanceMeasureReportingPeriodTargetsUpdated =
                    new List <GeospatialAreaPerformanceMeasureReportingPeriodTarget>();
                foreach (var pmrpSimple in PerformanceMeasureReportingPeriodSimples)
                {
                    // Reporting Period
                    // ----------------
                    var reportingPeriod = allPerformanceMeasureReportingPeriods.SingleOrDefault(x => x.PerformanceMeasureReportingPeriodCalendarYear == pmrpSimple.PerformanceMeasureReportingPeriodCalendarYear);
                    if (reportingPeriod == null)
                    {
                        reportingPeriod = new PerformanceMeasureReportingPeriod(pmrpSimple.PerformanceMeasureReportingPeriodCalendarYear,
                                                                                pmrpSimple.PerformanceMeasureReportingPeriodLabel);
                    }
                    var performanceMeasureTarget = allGeospatialAreaPerformanceMeasureReportingPeriodTargets.SingleOrDefault(x => x.GeospatialAreaPerformanceMeasureReportingPeriodTargetID == pmrpSimple.GeospatialAreaPerformanceMeasureReportingPeriodTargetID);
                    if (performanceMeasureTarget == null)
                    {
                        // ReSharper disable once RedundantAssignment
                        performanceMeasureTarget = new GeospatialAreaPerformanceMeasureReportingPeriodTarget(geospatialArea, performanceMeasure, reportingPeriod)
                        {
                            GeospatialAreaPerformanceMeasureTargetValue      = pmrpSimple.TargetValue,
                            GeospatialAreaPerformanceMeasureTargetValueLabel = pmrpSimple.TargetValueLabel
                        };
                    }
                    else
                    {
                        performanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValue      = pmrpSimple.TargetValue;
                        performanceMeasureTarget.GeospatialAreaPerformanceMeasureTargetValueLabel = pmrpSimple.TargetValueLabel;
                    }
                    geospatialAreaPerformanceMeasureReportingPeriodTargetsUpdated.Add(performanceMeasureTarget);
                }

                // we need to preserve any Geospatial Area targets for geospatial areas that are not the current one we are editing.
                geospatialAreaPerformanceMeasureReportingPeriodTargetsUpdated.AddRange(allGeospatialAreaPerformanceMeasureReportingPeriodTargets.Where(x => x.GeospatialAreaID != geospatialArea.GeospatialAreaID));

                // Perform the merge, which deletes the ones that haven't been submitted
                performanceMeasure.GeospatialAreaPerformanceMeasureReportingPeriodTargets.Merge(geospatialAreaPerformanceMeasureReportingPeriodTargetsUpdated,
                                                                                                allGeospatialAreaPerformanceMeasureReportingPeriodTargets,
                                                                                                (x, y) => x.GeospatialAreaPerformanceMeasureReportingPeriodTargetID == y.GeospatialAreaPerformanceMeasureReportingPeriodTargetID,
                                                                                                (x, y) =>
                {
                    x.GeospatialAreaPerformanceMeasureReportingPeriodTargetID = y.GeospatialAreaPerformanceMeasureReportingPeriodTargetID;
                }, HttpRequestStorage.DatabaseEntities);

                break;

            default:
                throw new ArgumentOutOfRangeException($"Invalid Target Value Type {performanceMeasureTargetValueTypeEnum}");
            }
            SetGoogleChartConfigurationForGeospatialAreaPerformanceMeasure(performanceMeasure, geospatialArea);
        }
        public void UpdateModel(ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure,
                                ICollection <PerformanceMeasureReportingPeriod> allPerformanceMeasureReportingPeriods,
                                ICollection <PerformanceMeasureReportingPeriodTarget> allPerformanceMeasureReportingPeriodTargets)
        {
            var performanceMeasureTargetValueTypeEnum = PerformanceMeasureTargetValueType.AllLookupDictionary[PerformanceMeasureTargetValueTypeID].ToEnum;

            DeleteOtherPerformanceMeasureTargetValueTypes(performanceMeasure, performanceMeasureTargetValueTypeEnum);

            switch (performanceMeasureTargetValueTypeEnum)
            {
            case PerformanceMeasureTargetValueTypeEnum.NoTarget:
                // Nothing to do here, there are no "No Targets" to be saved in this case. But we still need this so that the ArgumentOutOfRange validation works

                // need to reset the series for the geospatial json...


                break;

            case PerformanceMeasureTargetValueTypeEnum.FixedTarget:
                var fixedTarget = PerformanceMeasureFixedTargetModelExtensions.GetOrCreatePerformanceMeasureFixedTarget(performanceMeasure, FixedTargetValue.Value);
                fixedTarget.PerformanceMeasureTargetValueLabel = FixedTargetValueLabel;
                fixedTarget.PerformanceMeasureTargetValue      = FixedTargetValue;
                break;

            case PerformanceMeasureTargetValueTypeEnum.TargetPerYear:
                var performanceMeasureReportingPeriodTargetsUpdated = new List <PerformanceMeasureReportingPeriodTarget>();
                foreach (var pmrpSimple in PerformanceMeasureReportingPeriodSimples)
                {
                    // Reporting Period
                    // ----------------
                    var reportingPeriod = allPerformanceMeasureReportingPeriods.SingleOrDefault(x => x.PerformanceMeasureReportingPeriodCalendarYear == pmrpSimple.PerformanceMeasureReportingPeriodCalendarYear);
                    if (reportingPeriod == null)
                    {
                        reportingPeriod = new PerformanceMeasureReportingPeriod(pmrpSimple.PerformanceMeasureReportingPeriodCalendarYear, pmrpSimple.PerformanceMeasureReportingPeriodLabel);
                    }
                    var performanceMeasureTarget = allPerformanceMeasureReportingPeriodTargets.SingleOrDefault(x => x.PerformanceMeasureReportingPeriodTargetID == pmrpSimple.PerformanceMeasureReportingPeriodTargetID);
                    if (performanceMeasureTarget == null)
                    {
                        // ReSharper disable once RedundantAssignment
                        performanceMeasureTarget = new PerformanceMeasureReportingPeriodTarget(performanceMeasure, reportingPeriod)
                        {
                            PerformanceMeasureTargetValue      = pmrpSimple.TargetValue,
                            PerformanceMeasureTargetValueLabel = pmrpSimple.TargetValueLabel
                        };
                    }
                    else
                    {
                        performanceMeasureTarget.PerformanceMeasureTargetValue      = pmrpSimple.TargetValue;
                        performanceMeasureTarget.PerformanceMeasureTargetValueLabel = pmrpSimple.TargetValueLabel;
                    }
                    performanceMeasureReportingPeriodTargetsUpdated.Add(performanceMeasureTarget);
                }

                performanceMeasure.PerformanceMeasureReportingPeriodTargets.Merge(
                    performanceMeasureReportingPeriodTargetsUpdated,
                    allPerformanceMeasureReportingPeriodTargets,
                    (x, y) => x.PerformanceMeasureReportingPeriodTargetID == y.PerformanceMeasureReportingPeriodTargetID,
                    (x, y) =>
                {
                    x.PerformanceMeasureReportingPeriodTargetID = y.PerformanceMeasureReportingPeriodTargetID;
                }, HttpRequestStorage.DatabaseEntities);
                break;

            default:
                throw new ArgumentOutOfRangeException($"Invalid Target Value Type {performanceMeasureTargetValueTypeEnum}");
            }
            SetGoogleChartConfigurationForPerformanceMeasure(performanceMeasure, performanceMeasureTargetValueTypeEnum);
        }