Exemple #1
0
        public async Task <ActionResult> Index(long urn,
                                               UnitType unit = UnitType.AbsoluteMoney,
                                               CentralFinancingType financing = CentralFinancingType.Include,
                                               TabType tab        = TabType.Expenditure,
                                               ChartFormat format = ChartFormat.Charts)
        {
            if (FeatureManager.IsDisabled(Features.RevisedSchoolPage))
            {
                return(Redirect($"/school/detail?urn={urn}"));
            }

            OverwriteDefaultUnitTypeForSelectedTab(tab, ref unit);

            await _schoolVMBuilder.BuildCoreAsync(urn);

            _schoolVMBuilder.SetTab(tab);
            await _schoolVMBuilder.AddHistoricalChartsAsync(tab, DetectDefaultChartGroupFromTabType(tab), financing, unit);

            await _schoolVMBuilder.AddHistoricalChartsAsync(TabType.Workforce, DetectDefaultChartGroupFromTabType(TabType.Workforce), CentralFinancingType.Include, UnitType.AbsoluteCount);

            _schoolVMBuilder.SetChartGroups(tab);
            _schoolVMBuilder.AssignLaName();
            var schoolVM = _schoolVMBuilder.GetResult();

            var hasCscpUrl = await _cscpLookupService.CscpHasPage((int)urn, false);

            var hasGiasUrl = await _giasLookupService.GiasHasPage((int)urn, false);

            schoolVM.HasCscpUrl = hasCscpUrl;
            schoolVM.HasGiasUrl = hasGiasUrl;

            if (schoolVM.IsFederation)
            {
                return(Redirect("/federation/detail?fuid=" + schoolVM.Id));
            }

            if (schoolVM.ContextData == null)
            {
                return(View("EmptyResult", new SearchViewModel(_benchmarkBasketService.GetSchoolBenchmarkList(), SearchTypes.SEARCH_BY_NAME_ID)));
            }

            ViewBag.Tab                  = tab;
            ViewBag.ChartGroup           = schoolVM.HistoricalCharts.First().ChartGroup;
            ViewBag.UnitType             = schoolVM.HistoricalCharts.First().ShowValue;
            ViewBag.Financing            = financing;
            ViewBag.IsSATinLatestFinance = schoolVM.IsSATinLatestFinance;
            ViewBag.EstablishmentType    = schoolVM.EstablishmentType;
            ViewBag.ChartFormat          = format;

            return(View("Index", schoolVM));
        }
        public async Task <ActionResult> Detail(int?companyNo, int?uid = null, UnitType unit = UnitType.AbsoluteMoney, TabType tab = TabType.Expenditure, MatFinancingType financing = MatFinancingType.TrustAndAcademies, ChartFormat format = ChartFormat.Charts)
        {
            if (FeatureManager.IsDisabled(Features.RevisedSchoolPage))
            {
                return(Redirect($"/trust?companyNo={companyNo}&uid={uid}"));
            }

            if (companyNo == null && uid.HasValue)
            {
                var trustFinance = await _financialDataService.GetTrustFinancialDataObjectByUidAsync(uid.GetValueOrDefault(), await LatestMATTermAsync());

                companyNo = trustFinance.CompanyNumber;
                return(RedirectToActionPermanent("Detail", "Trust", new RouteValueDictionary {
                    { "companyNo", companyNo },
                    { "unit", unit },
                    { "tab", tab },
                    { "financing", financing },
                    { "format", format }
                }));
            }

            ChartGroupType chartGroup;

            switch (tab)
            {
            case TabType.Expenditure:
                chartGroup = ChartGroupType.TotalExpenditure;
                break;

            case TabType.Income:
                chartGroup = ChartGroupType.TotalIncome;
                break;

            case TabType.Balance:
                chartGroup = ChartGroupType.InYearBalance;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var trustVM = await BuildFullTrustVMAsync(companyNo.GetValueOrDefault(), tab, chartGroup, financing);

            var hasGiasUrl = await _giasLookupService.GiasHasPage(trustVM.UID.GetValueOrDefault(), true);

            var hasCscpUrl = await _cscpLookupService.CscpHasPage(trustVM.UID.GetValueOrDefault(), true);


            trustVM.HasCscpUrl = hasCscpUrl;
            trustVM.HasGiasUrl = hasGiasUrl;

            if (!trustVM.HasLatestYearFinancialData)
            {
                if (trustVM.AcademiesInFinanceList.Count == 1)
                {
                    return(RedirectToActionPermanent("Detail", "School", new RouteValueDictionary {
                        { "urn", trustVM.AcademiesInFinanceList.First().URN }
                    }));
                }
                return(RedirectToActionPermanent("SuggestTrust", "TrustSearch", new RouteValueDictionary {
                    { "trustNameId", companyNo }
                }));
            }

            UnitType unitType;

            switch (tab)
            {
            case TabType.Workforce:
                unitType = UnitType.AbsoluteCount;
                break;

            case TabType.Balance:
                unitType = unit == UnitType.AbsoluteMoney || unit == UnitType.PerPupil || unit == UnitType.PerTeacher ? unit : UnitType.AbsoluteMoney;
                break;

            default:
                unitType = unit;
                break;
            }

            _fcService.PopulateHistoricalChartsWithFinancialData(trustVM.HistoricalCharts, trustVM.HistoricalFinancialDataModels, trustVM.LatestTerm, tab, unitType, EstablishmentType.Academies);

            ViewBag.Tab               = tab;
            ViewBag.ChartGroup        = chartGroup;
            ViewBag.UnitType          = unitType;
            ViewBag.Financing         = financing;
            ViewBag.ChartFormat       = format;
            ViewBag.EstablishmentType = EstablishmentType.MAT;

            return(View("Detail", trustVM));
        }