public void UpdateModel(List <ProjectFirmaModels.Models.PerformanceMeasureActual> currentPerformanceMeasureActuals, IList <ProjectFirmaModels.Models.PerformanceMeasureActual> allPerformanceMeasureActuals, IList <PerformanceMeasureActualSubcategoryOption> allPerformanceMeasureActualSubcategoryOptions, ProjectFirmaModels.Models.Project project, IList <PerformanceMeasureReportingPeriod> allPerformanceMeasureReportingPeriods) { UpdateModelImpl(currentPerformanceMeasureActuals, allPerformanceMeasureActuals, allPerformanceMeasureActualSubcategoryOptions, allPerformanceMeasureReportingPeriods); var currentProjectExemptYears = project.GetPerformanceMeasuresExemptReportingYears(); HttpRequestStorage.DatabaseEntities.ProjectExemptReportingYears.Load(); var allProjectExemptYears = HttpRequestStorage.DatabaseEntities.AllProjectExemptReportingYears.Local; var projectExemptReportingYears = new List <ProjectExemptReportingYear>(); if (ProjectExemptReportingYears != null) { // Completely rebuild the list projectExemptReportingYears = ProjectExemptReportingYears.Where(x => x.IsExempt).Select(x => new ProjectExemptReportingYear(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; }
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 PerformanceMeasuresViewData(FirmaSession currentFirmaSession, ProjectFirmaModels.Models.Project project, ViewDataForAngularEditor viewDataForAngularEditor, ProposalSectionsStatus proposalSectionsStatus) : base(currentFirmaSession, project, ProjectCreateSection.ReportedAccomplishments.ProjectCreateSectionDisplayName, proposalSectionsStatus) { RefreshUrl = SitkaRoute <ProjectUpdateController> .BuildUrlFromExpression(x => x.RefreshReportedPerformanceMeasures(project)); DiffUrl = SitkaRoute <ProjectUpdateController> .BuildUrlFromExpression(x => x.DiffReportedPerformanceMeasures(project)); var performanceMeasureActuals = project.GetPerformanceMeasureReportedValues(); var performanceMeasureSubcategoriesCalendarYearReportedValues = PerformanceMeasureSubcategoriesCalendarYearReportedValue.CreateFromPerformanceMeasuresAndCalendarYears(new List <IPerformanceMeasureReportedValue>(performanceMeasureActuals)); PerformanceMeasureReportedValuesSummaryViewData = new PerformanceMeasureReportedValuesSummaryViewData(performanceMeasureSubcategoriesCalendarYearReportedValues, project.GetPerformanceMeasuresExemptReportingYears().Select(x => x.CalendarYear).ToList(), project.PerformanceMeasureActualYearsExemptionExplanation, performanceMeasureActuals.Select(x => x.CalendarYear).Distinct().Select(x => new CalendarYearString(x)).ToList()); ViewDataForAngular = viewDataForAngularEditor; IsImplementationStartYearValid = project.ImplementationStartYear.HasValue && project.ImplementationStartYear < project.CompletionYear; ReportingYearLabel = "Year"; if (new PerformanceMeasureManageFeature().HasPermissionByFirmaSession(currentFirmaSession)) { ConfigurePerformanceMeasuresUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(pmc => pmc.Manage()); } ShowCommentsSection = project.IsPendingApproval() || (project.ReportedAccomplishmentsComment != null && project.ProjectApprovalStatus == ProjectApprovalStatus.Returned); CanEditComments = project.IsPendingApproval() && new ProjectEditAsAdminRegardlessOfStageFeature().HasPermission(currentFirmaSession, project).HasPermission; }