public GridJsonNetJObjectResult <ProjectFundingSourceBudget> ProjectFundingSourceBudgetGridJsonData(FundingSourcePrimaryKey fundingSourcePrimaryKey)
        {
            var fundingSource = fundingSourcePrimaryKey.EntityObject;
            var projectFundingSourceBudgets = new List <ProjectFundingSourceBudget>();

            fundingSource.ProjectFundingSourceBudgets.GroupBy(x => x.ProjectID).ForEach(grouping =>
            {
                ProjectFundingSourceBudget aggregateProjectFundingSourceBudget = null;
                grouping.ForEach(x =>
                {
                    if (aggregateProjectFundingSourceBudget == null)
                    {
                        aggregateProjectFundingSourceBudget = x;
                    }
                    else
                    {
                        aggregateProjectFundingSourceBudget.SecuredAmount  += x.SecuredAmount;
                        aggregateProjectFundingSourceBudget.TargetedAmount += x.TargetedAmount;
                    }
                });
                projectFundingSourceBudgets.Add(aggregateProjectFundingSourceBudget);
            });
            var gridSpec = new ProjectFundingSourceBudgetGridSpec();
            var gridJsonNetJObjectResult = new GridJsonNetJObjectResult <ProjectFundingSourceBudget>(projectFundingSourceBudgets, gridSpec);

            return(gridJsonNetJObjectResult);
        }
        public ViewResult Detail(FundingSourcePrimaryKey fundingSourcePrimaryKey)
        {
            var fundingSource  = fundingSourcePrimaryKey.EntityObject;
            var taxonomyTrunks = HttpRequestStorage.DatabaseEntities.TaxonomyTrunks.ToList().SortByOrderThenName().ToList();

            const string chartTitle       = "Reported Expenditures";
            var          chartContainerID = chartTitle.Replace(" ", "");

            // If ProjectFundingSourceExpenditures is empty, ToGoogleChart returns null...
            var googleChart = fundingSource.ProjectFundingSourceExpenditures
                              .ToGoogleChart(x => x.Project.TaxonomyLeaf.TaxonomyBranch.TaxonomyTrunk.GetDisplayName(),
                                             taxonomyTrunks.Select(x => x.GetDisplayName()).ToList(),
                                             x => x.Project.TaxonomyLeaf.TaxonomyBranch.TaxonomyTrunk.GetDisplayName(),
                                             chartContainerID,
                                             fundingSource.GetDisplayName(),
                                             null);

            googleChart?.GoogleChartConfiguration.Legend.SetLegendPosition(GoogleChartLegendPosition.None);

            var projectFundingSourceBudgetGridSpec = new ProjectFundingSourceBudgetGridSpec()
            {
                ObjectNameSingular  = $"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}",
                ObjectNamePlural    = $"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabelPluralized()}",
                SaveFiltersInCookie = true
            };

            var viewGoogleChartViewData = new ViewGoogleChartViewData(googleChart, chartTitle, 350, false);

            var fundingSourceCustomAttributeTypes   = HttpRequestStorage.DatabaseEntities.FundingSourceCustomAttributeTypes.ToList().Where(x => x.HasViewPermission(CurrentFirmaSession));
            var projectCustomAttributeTypesViewData = new DisplayFundingSourceCustomAttributesViewData(
                fundingSourceCustomAttributeTypes.ToList(),
                new List <FundingSourceCustomAttribute>(fundingSource.FundingSourceCustomAttributes.ToList()));

            var viewData = new DetailViewData(CurrentFirmaSession, fundingSource, viewGoogleChartViewData, projectFundingSourceBudgetGridSpec, projectCustomAttributeTypesViewData);

            return(RazorView <Detail, DetailViewData>(viewData));
        }