Esempio n. 1
0
        /// <summary>
        /// Step 3 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="estType"></param>
        /// <param name="comparisonType"></param>
        /// <param name="areaType"></param>
        /// <param name="laCodeName"></param>
        /// <returns></returns>
        public async Task <ActionResult> AdvancedCharacteristics(
            long?urn,
            ComparisonType comparisonType,
            EstablishmentType estType,
            ComparisonArea?areaType,
            string laCodeName,
            BenchmarkCriteria AdvancedCriteria,
            bool excludePartial = false,
            int?laCode          = null)
        {
            if (!areaType.HasValue)
            {
                SchoolViewModel vm = null;
                if (urn.HasValue)
                {
                    vm = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());
                }
                else
                {
                    vm = new SchoolViewModelWithNoDefaultSchool();
                }
                vm.ErrorMessage        = ErrorMessages.SelectAreaType;
                ViewBag.Authorities    = _laService.GetLocalAuthorities();
                ViewBag.URN            = urn;
                ViewBag.ComparisonType = comparisonType;
                ViewBag.EstType        = estType;
                ViewBag.AreaType       = areaType;
                ViewBag.ExcludePartial = excludePartial.ToString();
                return(View("ChooseRegion", vm));
            }


            if (areaType == ComparisonArea.LaCodeName && laCode == null)
            {
                string errorMessage = _valService.ValidateLaCodeNameParameter(laCodeName);

                if (string.IsNullOrEmpty(errorMessage))
                {
                    if (IsNumeric(laCodeName))
                    {
                        laCode = int.Parse(laCodeName);
                        if (!_laSearchService.LaCodesContain(laCode.Value))
                        {
                            errorMessage = SearchErrorMessages.NO_LA_RESULTS;
                        }
                    }
                    else
                    {
                        var exactLaMatch = _laSearchService.SearchExactMatch(laCodeName);
                        if (exactLaMatch == null)
                        {
                            errorMessage = SearchErrorMessages.NO_LA_RESULTS;
                        }
                        else
                        {
                            laCode = int.Parse(exactLaMatch.Id);
                        }
                    }
                }

                if (errorMessage != null)
                {
                    SchoolViewModel vm = null;
                    if (urn.HasValue)
                    {
                        vm = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());
                    }
                    else
                    {
                        vm = new SchoolViewModelWithNoDefaultSchool();
                    }
                    vm.ErrorMessage        = errorMessage;
                    ViewBag.Authorities    = _laService.GetLocalAuthorities();
                    ViewBag.URN            = urn;
                    ViewBag.ComparisonType = comparisonType;
                    ViewBag.EstType        = estType;
                    ViewBag.AreaType       = areaType;
                    ViewBag.ExcludePartial = excludePartial.ToString();
                    return(View("ChooseRegion", vm));
                }
            }

            SchoolViewModel benchmarkSchoolVM;

            if (urn.HasValue)
            {
                benchmarkSchoolVM = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());

                var schoolsLatestFinancialDataModel = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(benchmarkSchoolVM.Id, benchmarkSchoolVM.EstablishmentType);

                benchmarkSchoolVM.HistoricalFinancialDataModels = new List <FinancialDataModel> {
                    schoolsLatestFinancialDataModel
                };
            }
            else
            {
                benchmarkSchoolVM = new SchoolViewModelWithNoDefaultSchool();
            }

            var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchoolVM, _benchmarkBasketService.GetSchoolBenchmarkList(), AdvancedCriteria);

            ViewBag.URN                 = urn;
            ViewBag.ComparisonType      = comparisonType;
            ViewBag.EstType             = estType;
            ViewBag.EstTypeDescription  = estType.GetDescription();
            ViewBag.ExcludePartial      = excludePartial.ToString();
            ViewBag.AreaType            = areaType;
            ViewBag.AreaTypeDescription = areaType == ComparisonArea.All ? "All of England" : _laService.GetLaName(laCode.ToString());
            ViewBag.LaCode              = laCode;

            return(View(schoolCharsVM));
        }