/// <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"));
            }
        }
Exemple #2
0
 public BenchmarkChartListViewModel(List <ChartViewModel> modelList, SchoolComparisonListModel comparisonList, List <ChartViewModel> chartGroups,
                                    ComparisonType comparisonType, BenchmarkCriteria advancedCriteria, SimpleCriteria simpleCriteria, BestInClassCriteria bicCriteria,
                                    FinancialDataModel benchmarkSchoolData, EstablishmentType estabType, EstablishmentType searchedEstabType, string schoolArea, string selectedArea,
                                    string latestTermAcademies, string latestTermMaintained, ComparisonArea areaType, string laCode, long?urn, int basketSize,
                                    TrustComparisonListModel trustComparisonList = null, List <EstablishmentViewModelBase> comparisonSchools = null, bool excludePartial = false)
     : base(modelList, comparisonList)
 {
     this.ChartGroups               = chartGroups;
     this.AdvancedCriteria          = advancedCriteria;
     this.SimpleCriteria            = simpleCriteria;
     this.BicCriteria               = bicCriteria;
     this.ComparisonType            = comparisonType;
     this.BenchmarkSchoolData       = benchmarkSchoolData;
     this.EstablishmentType         = estabType;
     this.SearchedEstablishmentType = searchedEstabType;
     this.SchoolArea           = schoolArea;
     this.SelectedArea         = selectedArea;
     this.TrustComparisonList  = trustComparisonList;
     this.LatestTermAcademies  = latestTermAcademies;
     this.LatestTermMaintained = latestTermMaintained;
     this.AreaType             = areaType;
     this.LaCode            = laCode;
     this.URN               = urn;
     this.BasketSize        = basketSize;
     this.ComparisonSchools = comparisonSchools;
     this.ExcludePartial    = excludePartial;
 }
Exemple #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"));
            }
        }
Exemple #4
0
        public async Task <ActionResult> Index(
            string urn,
            SimpleCriteria simpleCriteria,
            BenchmarkCriteria benchmarkCriteria,
            int basketSize = ComparisonListLimit.DEFAULT,
            SchoolFinancialDataModel benchmarkSchoolData = null,
            EstablishmentType searchedEstabType          = EstablishmentType.All,
            ComparisonType comparisonType = ComparisonType.Manual,
            ComparisonArea areaType       = ComparisonArea.All,
            string laCode                  = null,
            RevenueGroupType tab           = RevenueGroupType.Expenditure,
            CentralFinancingType financing = CentralFinancingType.Include)
        {
            ChartGroupType chartGroup;

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

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

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

            case RevenueGroupType.Workforce:
                chartGroup = ChartGroupType.Workforce;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var defaultUnitType = tab == RevenueGroupType.Workforce ? UnitType.AbsoluteCount : UnitType.AbsoluteMoney;
            var benchmarkCharts = await BuildSchoolBenchmarkChartsAsync(tab, chartGroup, defaultUnitType, financing);

            var establishmentType = DetectEstablishmentType(base.ExtractSchoolComparisonListFromCookie());

            var chartGroups = _benchmarkChartBuilder.Build(tab, establishmentType).DistinctBy(c => c.ChartGroup).ToList();

            string selectedArea = "";

            switch (areaType)
            {
            case ComparisonArea.All:
                selectedArea = "All England";
                break;

            case ComparisonArea.LaCode:
            case ComparisonArea.LaName:
                selectedArea = _laService.GetLaName(laCode);
                break;
            }

            string schoolArea = "";

            if (benchmarkSchoolData != null)
            {
                schoolArea = _laService.GetLaName(benchmarkSchoolData.LaNumber.ToString());
            }

            var academiesTerm  = FormatHelpers.FinancialTermFormatAcademies(_financialDataService.GetLatestDataYearPerSchoolType(SchoolFinancialType.Academies));
            var maintainedTerm = FormatHelpers.FinancialTermFormatMaintained(_financialDataService.GetLatestDataYearPerSchoolType(SchoolFinancialType.Maintained));

            var vm = new BenchmarkChartListViewModel(benchmarkCharts, base.ExtractSchoolComparisonListFromCookie(), chartGroups, comparisonType, benchmarkCriteria, simpleCriteria, benchmarkSchoolData, establishmentType, searchedEstabType, schoolArea, selectedArea, academiesTerm, maintainedTerm, areaType, laCode, urn, basketSize);

            ViewBag.Tab               = tab;
            ViewBag.ChartGroup        = chartGroup;
            ViewBag.UnitType          = defaultUnitType;
            ViewBag.HomeSchoolId      = vm.SchoolComparisonList.HomeSchoolUrn;
            ViewBag.EstablishmentType = vm.EstablishmentType;
            ViewBag.Financing         = financing;
            ViewBag.ChartFormat       = ChartFormat.Charts;

            return(View("Index", vm));
        }
Exemple #5
0
        public async Task <ActionResult> GenerateFromAdvancedCriteria(BenchmarkCriteria criteria, EstablishmentType estType, int?lacode, string urn, ComparisonArea areaType, BenchmarkListOverwriteStrategy overwriteStrategy = BenchmarkListOverwriteStrategy.Overwrite)
        {
            criteria.LocalAuthorityCode = lacode;
            var benchmarkSchool = InstantiateBenchmarkSchool(urn);

            switch (overwriteStrategy)
            {
            case BenchmarkListOverwriteStrategy.Overwrite:
                var result = await _comparisonService.GenerateBenchmarkListWithAdvancedComparisonAsync(criteria, estType);

                var cookie = base.UpdateSchoolComparisonListCookie(CompareActions.CLEAR_BENCHMARK_LIST, null);
                Response.Cookies.Add(cookie);

                foreach (var schoolDoc in result.BenchmarkSchools)
                {
                    var benchmarkSchoolToAdd = new BenchmarkSchoolViewModel()
                    {
                        Name          = schoolDoc.GetPropertyValue <string>("School Name"),
                        Type          = schoolDoc.GetPropertyValue <string>("Type"),
                        FinancialType = schoolDoc.GetPropertyValue <string>("FinanceType") == "A" ? SchoolFinancialType.Academies.ToString() : SchoolFinancialType.Maintained.ToString(),
                        Urn           = schoolDoc.GetPropertyValue <string>("URN")
                    };
                    cookie = base.UpdateSchoolComparisonListCookie(CompareActions.ADD_TO_COMPARISON_LIST, benchmarkSchoolToAdd);
                    Response.Cookies.Add(cookie);
                }
                break;

            case BenchmarkListOverwriteStrategy.Add:
                var comparisonList   = base.ExtractSchoolComparisonListFromCookie();
                var comparisonResult = await _comparisonService.GenerateBenchmarkListWithAdvancedComparisonAsync(criteria, estType, ComparisonListLimit.LIMIT - comparisonList.BenchmarkSchools.Count);

                foreach (var schoolDoc in comparisonResult.BenchmarkSchools)
                {
                    var benchmarkSchoolToAdd = new BenchmarkSchoolViewModel()
                    {
                        Name          = schoolDoc.GetPropertyValue <string>("School Name"),
                        Type          = schoolDoc.GetPropertyValue <string>("Type"),
                        FinancialType = schoolDoc.GetPropertyValue <string>("FinanceType") == "A" ? SchoolFinancialType.Academies.ToString() : SchoolFinancialType.Maintained.ToString(),
                        Urn           = schoolDoc.GetPropertyValue <string>("URN")
                    };
                    cookie = base.UpdateSchoolComparisonListCookie(CompareActions.ADD_TO_COMPARISON_LIST, benchmarkSchoolToAdd);
                    Response.Cookies.Add(cookie);
                }

                break;
            }

            AddDefaultBenchmarkSchoolToList();

            return(await Index(urn, null,
                               criteria, ComparisonListLimit.DEFAULT, benchmarkSchool.HistoricalSchoolFinancialDataModels.Last(), estType, ComparisonType.Advanced, areaType, lacode.ToString()));
        }
 public BenchmarkChartListViewModel(List <ChartViewModel> modelList, ComparisonListModel comparisonList, List <ChartViewModel> chartGroups, ComparisonType comparisonType, BenchmarkCriteria advancedCriteria, SimpleCriteria simpleCriteria, SchoolFinancialDataModel benchmarkSchoolData, EstablishmentType estabType, EstablishmentType searchedEstabType, string schoolArea, string selectedArea, string latestTermAcademies, string latestTermMaintained, ComparisonArea areaType, string laCode, string urn, int basketSize, TrustComparisonViewModel trustComparisonList = null)
 {
     base.SchoolComparisonList      = comparisonList;
     base.ModelList                 = modelList;
     this.ChartGroups               = chartGroups;
     this.AdvancedCriteria          = advancedCriteria;
     this.SimpleCriteria            = simpleCriteria;
     this.ComparisonType            = comparisonType;
     this.BenchmarkSchoolData       = benchmarkSchoolData;
     this.EstablishmentType         = estabType;
     this.SearchedEstablishmentType = searchedEstabType;
     this.SchoolArea                = schoolArea;
     this.SelectedArea              = selectedArea;
     this.TrustComparisonList       = trustComparisonList;
     this.LatestTermAcademies       = latestTermAcademies;
     this.LatestTermMaintained      = latestTermMaintained;
     this.AreaType   = areaType;
     this.LaCode     = laCode;
     this.URN        = urn;
     this.BasketSize = basketSize;
 }