public void UpdateModel(FirmaSession currentFirmaSession, ProjectFirmaModels.Models.PerformanceMeasure performanceMeasure) { if (GeospatialAreas == null || !GeospatialAreas.Any()) { return; } foreach (var geospatialAreaID in GeospatialAreas) { var geospatialArea = HttpRequestStorage.DatabaseEntities.GeospatialAreas.Single(x => x.GeospatialAreaID == geospatialAreaID); if (geospatialArea == null) { //bad geospatialAreaID from front-end continue; } // Default to a "No Target" var noTarget = GeospatialAreaPerformanceMeasureNoTargetModelExtensions.GetOrCreateGeospatialAreaPerformanceMeasureNoTarget(performanceMeasure, geospatialArea); HttpRequestStorage.DatabaseEntities.AllGeospatialAreaPerformanceMeasureNoTargets.Add(noTarget); } HttpRequestStorage.DatabaseEntities.SaveChanges(currentFirmaSession); }
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); }