/// <summary>
        /// Step 4 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="comparisonType"></param>
        /// <param name="estType"></param>
        /// <param name="criteria"></param>
        /// <param name="areaType"></param>
        /// <param name="lacode"></param>
        /// <param name="schoolName"></param>
        /// <returns></returns>
        public ActionResult OverwriteStrategy(string urn, ComparisonType comparisonType, EstablishmentType estType, BenchmarkCriteriaVM criteria, ComparisonArea areaType, int?lacode, string schoolName)
        {
            ViewBag.URN            = urn;
            ViewBag.HomeSchoolName = schoolName;
            ViewBag.ComparisonType = comparisonType;
            ViewBag.EstType        = estType;
            ViewBag.AreaType       = areaType;
            ViewBag.LaCode         = lacode;

            var benchmarkList = base.ExtractSchoolComparisonListFromCookie();

            if (!ModelState.IsValid)
            {
                var benchmarkSchool = new SchoolViewModel(_contextDataService.GetSchoolByUrn(urn), benchmarkList);
                var latestYear      = _financialDataService.GetLatestDataYearPerSchoolType(benchmarkSchool.FinancialType);
                var term            = FormatHelpers.FinancialTermFormatAcademies(latestYear);
                var document        = _financialDataService.GetSchoolDataDocument(urn, term, benchmarkSchool.FinancialType);
                benchmarkSchool.HistoricalSchoolFinancialDataModels = new List <SchoolFinancialDataModel> {
                    new SchoolFinancialDataModel(urn, term, document, benchmarkSchool.FinancialType)
                };
                var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchool, benchmarkList, new BenchmarkCriteria());
                schoolCharsVM.ErrorMessage = "Validation Error";
                return(View("AdvancedCharacteristics", schoolCharsVM));
            }

            if ((benchmarkList.BenchmarkSchools.Count > 1) ||
                (benchmarkList.BenchmarkSchools.Count == 1 && benchmarkList.BenchmarkSchools[0].Urn != benchmarkList.HomeSchoolUrn))
            {
                criteria.ComparisonList = benchmarkList;
                return(View(criteria));
            }
            else
            {
                TempData["URN"] = urn;
                TempData["BenchmarkCriteria"] = criteria.AdvancedCriteria;
                TempData["EstType"]           = estType;
                TempData["AreaType"]          = areaType;
                TempData["LaCode"]            = lacode;

                return(RedirectToAction("GenerateNewFromAdvancedCriteria", "BenchmarkCharts"));
            }
        }
        /// <summary>
        /// Step 3 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="estType"></param>
        /// <param name="comparisonType"></param>
        /// <param name="areaType"></param>
        /// <param name="lacode"></param>
        /// <returns></returns>
        public ActionResult AdvancedCharacteristics(string urn, ComparisonType comparisonType, EstablishmentType estType, ComparisonArea?areaType, int?lacode,
                                                    string laNameText, BenchmarkCriteria AdvancedCriteria)
        {
            if (areaType == ComparisonArea.LaName && !string.IsNullOrEmpty(laNameText) && lacode == null)
            {
                var exactLaMatch = _laSearchService.SearchExactMatch(laNameText);
                if (exactLaMatch != null)
                {
                    lacode = Int32.Parse(exactLaMatch.id);
                }
            }

            ViewBag.URN            = urn;
            ViewBag.ComparisonType = comparisonType;
            ViewBag.EstType        = estType;
            ViewBag.AreaType       = areaType;
            ViewBag.LaCode         = lacode;

            var benchmarkSchool = new SchoolViewModel(_contextDataService.GetSchoolByUrn(urn), base.ExtractSchoolComparisonListFromCookie());
            var latestYear      = _financialDataService.GetLatestDataYearPerSchoolType(benchmarkSchool.FinancialType);
            var term            = FormatHelpers.FinancialTermFormatAcademies(latestYear);
            var document        = _financialDataService.GetSchoolDataDocument(urn, term, benchmarkSchool.FinancialType);

            benchmarkSchool.HistoricalSchoolFinancialDataModels = new List <SchoolFinancialDataModel> {
                new SchoolFinancialDataModel(urn, term, document, benchmarkSchool.FinancialType)
            };

            if (!IsAreaFieldsValid(areaType, lacode, benchmarkSchool))
            {
                ViewBag.Authorities = _laService.GetLocalAuthorities();
                return(View("ChooseRegion", benchmarkSchool));
            }

            var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchool, base.ExtractSchoolComparisonListFromCookie(), AdvancedCriteria);

            return(View(schoolCharsVM));
        }
示例#3
0
        public async Task <ActionResult> OverwriteStrategy(long?urn, ComparisonType comparisonType, EstablishmentType estType, BenchmarkCriteriaVM criteria,
                                                           ComparisonArea areaType, int?lacode, string schoolName, int basketCount, bool excludePartial = false)
        {
            ViewBag.URN            = urn;
            ViewBag.HomeSchoolName = schoolName;
            ViewBag.ComparisonType = comparisonType;
            ViewBag.EstType        = estType;
            ViewBag.AreaType       = areaType;
            ViewBag.LaCode         = lacode;
            ViewBag.ExcludePartial = excludePartial.ToString();

            var benchmarkList = _benchmarkBasketService.GetSchoolBenchmarkList();

            if (!ModelState.IsValid)
            {
                if (urn.HasValue)
                {
                    var benchmarkSchool = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), benchmarkList);
                    var schoolsLatestFinancialDataModel = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(benchmarkSchool.Id, benchmarkSchool.EstablishmentType);

                    benchmarkSchool.HistoricalFinancialDataModels = new List <FinancialDataModel> {
                        schoolsLatestFinancialDataModel
                    };
                    var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchool, benchmarkList, new BenchmarkCriteria());
                    schoolCharsVM.ErrorMessage = "Validation Error";
                    return(View("AdvancedCharacteristics", schoolCharsVM));
                }
                else
                {
                    var schoolCharsVM = new SchoolCharacteristicsViewModel(new SchoolViewModelWithNoDefaultSchool(), benchmarkList, new BenchmarkCriteria());
                    schoolCharsVM.ErrorMessage = "Validation Error";
                    return(View("AdvancedCharacteristics", schoolCharsVM));
                }
            }

            if ((benchmarkList.BenchmarkSchools.Count > 1) ||
                (benchmarkList.BenchmarkSchools.Count == 1 && benchmarkList.BenchmarkSchools[0].Urn != benchmarkList.HomeSchoolUrn))
            {
                criteria.ComparisonList = benchmarkList;
                if (criteria.AdvancedCriteria == null)
                {
                    criteria.AdvancedCriteria = new BenchmarkCriteria();
                }
                if (benchmarkList.BenchmarkSchools.Count + basketCount > ComparisonListLimit.LIMIT)
                {
                    return(View("OverwriteReplace", criteria));
                }
                else
                {
                    return(View(criteria));
                }
            }
            else
            {
                TempData["URN"] = urn;
                TempData["BenchmarkCriteria"] = criteria.AdvancedCriteria;
                TempData["EstType"]           = estType;
                TempData["AreaType"]          = areaType;
                TempData["LaCode"]            = lacode;
                TempData["ExcludePartial"]    = excludePartial;

                return(RedirectToAction("GenerateNewFromAdvancedCriteria", "BenchmarkCharts"));
            }
        }
示例#4
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));
        }