public BiOpAnnualReportGridSpec(List <GeospatialAreaType> geoSpatialAreaTypesToInclude, List <ProjectFirmaModels.Models.PerformanceMeasure> performanceMeasuresToInclude, GridOutputFormat gridOutputFormat) { AllProjectedFundingValues = HttpRequestStorage.DatabaseEntities.Projects.ToList().Select(p => (double)p.GetProjectedFunding() + (double)p.GetNoFundingSourceIdentifiedAmountOrZero()).ToList(); Add("Population Type", barr => barr.GeospatialAreaType?.GeospatialAreaTypeName ?? "None Selected", 150, DhtmlxGridColumnFilterType.SelectFilterStrict); if (gridOutputFormat == GridOutputFormat.Csv) { Add(FieldDefinitionEnum.Project.ToType().FieldDefinitionDisplayName, barr => barr.Project.ProjectName, 250, DhtmlxGridColumnFilterType.Html); } else { Add(FieldDefinitionEnum.Project.ToType().FieldDefinitionDisplayName, barr => barr.Project.GetDisplayNameAsUrl(), 250, DhtmlxGridColumnFilterType.Html); } Add("Year", barr => barr.PerformanceMeasureActual.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodLabel, 100, DhtmlxGridColumnFilterType.SelectFilterStrict); Add("WBS Number", barr => barr.Project.CostAuthorityProjects.FirstOrDefault(cap => cap.IsPrimaryProjectCawbs)?.CostAuthority.CostAuthorityWorkBreakdownStructure, 150, DhtmlxGridColumnFilterType.Text); Add($"{FieldDefinitionEnum.ProjectStage.ToType().FieldDefinitionDisplayName}", barr => barr.Project.ProjectStage.ProjectStageDisplayName, 150, DhtmlxGridColumnFilterType.SelectFilterStrict); Add("Basin Liason", barr => String.Join(",", barr.Project.ProjectGeospatialAreas.Select(pga => pga.GeospatialArea).ToList().GetSubbasinLiasonList().Select(pr => pr.GetFullNameFirstLast())), 100, DhtmlxGridColumnFilterType.SelectFilterStrict); // from the project location simple point. Maybe we could find a center from detailed locations if the project doesn't have a simple location? -- SMG 8/11/2020 Add("Lat", barr => $"{barr.Project.ProjectLocationPoint?.YCoordinate.ToString()}", 75, DhtmlxGridColumnFilterType.Numeric); Add("Lng", barr => $"{barr.Project.ProjectLocationPoint?.XCoordinate.ToString()}", 75, DhtmlxGridColumnFilterType.Numeric); Add("ESU/DPS", barr => barr.GeospatialAreaType.GetEsuDpsPopulationStringForProjectInBiOpAnnualReportGrid(barr.Project, gridOutputFormat != GridOutputFormat.Csv).ToHTMLFormattedString(), 100, DhtmlxGridColumnFilterType.Html); Add("MPG", barr => barr.GeospatialAreaType.GetMpgPopulationStringForProjectInBiOpAnnualReportGrid(barr.Project, gridOutputFormat != GridOutputFormat.Csv).ToHTMLFormattedString(), 100, DhtmlxGridColumnFilterType.Html); Add("Population", barr => barr.GeospatialAreaType.GetPopulationStringForProjectInBiOpAnnualReportGrid(barr.Project, gridOutputFormat != GridOutputFormat.Csv).ToHTMLFormattedString(), 100, DhtmlxGridColumnFilterType.Html); foreach (var geospatialAreaType in geoSpatialAreaTypesToInclude) { if (gridOutputFormat == GridOutputFormat.Csv) { Add(geospatialAreaType.GeospatialAreaTypeName, barr => String.Join(",", barr.Project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).Select(x => x.GeospatialArea.GetDisplayName())).ToHTMLFormattedString(), 100, DhtmlxGridColumnFilterType.Html); } else { Add(geospatialAreaType.GeospatialAreaTypeName, barr => String.Join(",", barr.Project.ProjectGeospatialAreas.Where(x => x.GeospatialArea.GeospatialAreaTypeID == geospatialAreaType.GeospatialAreaTypeID).Select(x => x.GeospatialArea.GetDisplayNameAsUrl())).ToHTMLFormattedString(), 100, DhtmlxGridColumnFilterType.Html); } } Add("Project Cost", barr => (double)barr.Project.GetProjectedFunding() + (double)barr.Project.GetNoFundingSourceIdentifiedAmountOrZero(), 100, DhtmlxGridColumnFormatType.Decimal); Add("Project Cost Category", barr => barr.Project.GetProjectedFundingCategory(AllProjectedFundingValues), 100, DhtmlxGridColumnFilterType.SelectFilterStrict); Add("Is BPA Funded", barr => barr.Project.IsBPAFunded() ? "Yes" : "No", 75, DhtmlxGridColumnFilterType.SelectFilterStrict); Add("Sponsor Organization", barr => barr.Project.GetPrimaryContactOrganization()?.OrganizationName ?? "", 200, DhtmlxGridColumnFilterType.SelectFilterStrict); foreach (var performanceMeasure in performanceMeasuresToInclude) { Add(performanceMeasure.PerformanceMeasureDisplayName, barr => performanceMeasure.PerformanceMeasureActuals.Where(pma => pma.ProjectID == barr.Project.ProjectID && pma.PerformanceMeasureReportingPeriod == barr.PerformanceMeasureActual.PerformanceMeasureReportingPeriod) .Sum(pma => pma.ActualValue), 50, DhtmlxGridColumnFormatType.Decimal); } }
private static BiOpAnnualReportGridSpec BiOpAnnualReportGridSpec(GridOutputFormat gridOutputFormat, out List <BiOpAnnualReportRow> rows, bool includeBPAFunded) { var populationAreaTypeIDs = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes .Where(x => x.IsPopulation).Select(x => x.GeospatialAreaTypeID).ToList(); var performanceMeasuresToInclude = HttpRequestStorage.DatabaseEntities.PerformanceMeasures .Where(pm => pm.IncludeInBiOpAnnualReport).ToList(); var geoSpatialAreasToInclude = HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes.Where(x => x.IncludeInBiOpAnnualReport).ToList(); var biOpAnnualReportGridSpec = new BiOpAnnualReportGridSpec(geoSpatialAreasToInclude, performanceMeasuresToInclude, gridOutputFormat); var linqQuery = from p in HttpRequestStorage.DatabaseEntities.Projects join pma in HttpRequestStorage.DatabaseEntities.PerformanceMeasureActuals on p.ProjectID equals pma.ProjectID join pmrp in HttpRequestStorage.DatabaseEntities.PerformanceMeasureReportingPeriods on pma .PerformanceMeasureReportingPeriodID equals pmrp .PerformanceMeasureReportingPeriodID join pga in HttpRequestStorage.DatabaseEntities.ProjectGeospatialAreas on p.ProjectID equals pga.ProjectID into pgaJoin from pga in pgaJoin.DefaultIfEmpty() join ga in HttpRequestStorage.DatabaseEntities.GeospatialAreas on pga.GeospatialAreaID equals ga .GeospatialAreaID into gaJoin from ga in gaJoin.DefaultIfEmpty() join gat in HttpRequestStorage.DatabaseEntities.GeospatialAreaTypes.Where(x => populationAreaTypeIDs.Contains(x.GeospatialAreaTypeID)) on ga.GeospatialAreaTypeID equals gat .GeospatialAreaTypeID into gatJoin from gat in gatJoin.DefaultIfEmpty() where populationAreaTypeIDs.Contains(gat.GeospatialAreaTypeID) || gat == null select new BiOpAnnualReportRow { PerformanceMeasureActual = pma, Project = p, GeospatialAreaType = gat }; // the query and grouping is kind of odd here. But I think it ultimately gets the job done according to the evolving spec - SMG 9/10/2020 [PF-2198] var groupedRows = linqQuery.ToList().GroupBy(x => $"{x.PerformanceMeasureActual.PerformanceMeasureReportingPeriodID}{x.Project.ProjectID}"); rows = new List <BiOpAnnualReportRow>(); foreach (var groupedRow in groupedRows) { if (groupedRow.Any(x => x.GeospatialAreaType != null)) { rows.AddRange(groupedRow.Where(x => x.GeospatialAreaType != null).DistinctBy(x => $"{x.GeospatialAreaType?.GeospatialAreaTypeID}{x.PerformanceMeasureActual.PerformanceMeasureReportingPeriodID}{x.Project.ProjectID}")); } else { rows.Add(groupedRow.FirstOrDefault()); } } // exclude bpa funded rows from the output rows = includeBPAFunded ? rows : rows.Where(x => !x.Project.IsBPAFunded()).ToList(); return(biOpAnnualReportGridSpec); }