public async Task <int> GetEstablishmentRecordCountAsync(string term, EstablishmentType estType)
        {
            var collectionName = string.Empty;

            switch (estType)
            {
            case EstablishmentType.Academies:
                collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, DataGroups.MATAllocs);

                break;

            case EstablishmentType.Maintained:
                collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, DataGroups.Maintained);

                break;

            case EstablishmentType.MAT:
                collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, DataGroups.MATOverview);

                break;
            }

            var container = _client.GetContainer(_databaseId, collectionName);

            var queryDefinition = new QueryDefinition("SELECT VALUE COUNT(c) FROM c");

            var feedIterator = container.GetItemQueryIterator <int>(queryDefinition, null);

            var result = (await feedIterator.ReadNextAsync()).FirstOrDefault();

            return(result);
        }
 public FinancialDataModel(string id, string term, SchoolTrustFinancialDataObject financialDataObject, EstablishmentType estabType)
 {
     Id   = id;
     Term = term;
     FinancialDataObjectModel = financialDataObject;
     EstabType = estabType;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
        public static string ToDataGroup(this EstablishmentType estabType, CentralFinancingType cFinance)
        {
            switch (estabType)
            {
            case EstablishmentType.Academies:
                return((cFinance == CentralFinancingType.Include) ? DataGroups.MATAllocs : DataGroups.Academies);

            default:
                return(estabType.ToDataGroup());
            }
        }
Exemplo n.º 5
0
        public void Should_Construct_EstablishmentType()
        {
            EstablishmentType establishmentType = new EstablishmentType();

            _ = establishmentType.EstablishmentTypeId;
            _ = establishmentType.Name;
            _ = establishmentType.Size;
            _ = establishmentType.CommercialRegistrationNo;

            establishmentType.ShouldNotBeNull();
        }
Exemplo n.º 6
0
        public EstablishmentViewModel(EstablishmentType establishmentType)
        {
            _establishmentType = establishmentType;
            SearchCommand      = new Command(Search);
            DetailCommand      = new Command <Establishment>(Detail);

            var allEstablishment = new EstablishmentService().GetEstablishments();
            var allStores        = allEstablishment.Where(a => a.Type == _establishmentType).ToList();

            Establishments     = allStores;
            _allEstablishments = allStores;
        }
        /// <summary>
        /// Step 2 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="comparisonType"></param>
        /// <param name="estType"></param>
        /// <returns></returns>
        public ViewResult ChooseRegion(int urn, ComparisonType comparisonType, EstablishmentType estType)
        {
            ViewBag.URN            = urn;
            ViewBag.ComparisonType = comparisonType;
            ViewBag.EstType        = estType;
            ViewBag.AreaType       = ComparisonArea.All;
            ViewBag.Authorities    = _laService.GetLocalAuthorities();

            var benchmarkSchool = new SchoolViewModel(_contextDataService.GetSchoolByUrn(urn.ToString()), base.ExtractSchoolComparisonListFromCookie());

            return(View("ChooseRegion", benchmarkSchool));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> DataSet(EstablishmentType estab, string year)
        {
            if (string.IsNullOrEmpty(year))
            {
                ViewBag.ErrorMessage = "Select an academic year";
                return(AcademicYear(estab));
            }

            ViewBag.Estab = estab;
            ViewBag.Year  = year;
            ViewBag.Count = await _dataService.GetEstablishmentRecordCountAsync(year, estab);

            return(View());
        }
 public void PopulateHistoricalChartsWithFinancialData(List <ChartViewModel> historicalCharts,
                                                       List <FinancialDataModel> SchoolFinancialDataModels, string term, TabType revgroup, UnitType unit,
                                                       EstablishmentType estabType)
 {
     foreach (var chart in historicalCharts.Where(c => revgroup == c.TabType || revgroup == TabType.AllIncludingSchoolPerf || revgroup == TabType.AllExcludingSchoolPerf))
     {
         BuildChart(SchoolFinancialDataModels, term, revgroup, unit, estabType, chart);
         if (chart.SubCharts != null)
         {
             foreach (var subChart in chart.SubCharts)
             {
                 BuildChart(SchoolFinancialDataModels, term, revgroup, unit, estabType, subChart);
             }
         }
     }
 }
        private string GenerateJson(List <HistoricalChartData> historicalChartData,
                                    EstablishmentType estabType)
        {
            var clonedHistoricalChartDataList = new List <HistoricalChartData>();

            foreach (var chartData in historicalChartData)
            {
                var clonedChartData = (HistoricalChartData)chartData.Clone();
                clonedChartData.Year = (estabType == EstablishmentType.Academies || estabType == EstablishmentType.MAT)
                    ? clonedChartData.Year.Replace(" / ", "/")
                    : clonedChartData.Year.Replace(" / ", "-");
                clonedChartData.Year = clonedChartData.Year.Remove(5, 2);

                clonedHistoricalChartDataList.Add(clonedChartData);
            }
            return(JsonConvert.SerializeObject(clonedHistoricalChartDataList));
        }
Exemplo n.º 11
0
        public EstablishmentViewModel(EstablishmentType establishmenType)
        {
            if (String.IsNullOrEmpty(SearchWord))
            {
                SearchWord = "";
            }
            _establishmenType = establishmenType;
            //faz o vinculo na hora que carrega a pagina
            SearchCommand = new Command(Search);
            //Indica o tipo de objeto que vai tá passando no parametro
            DetailCommand = new Command <Establishment>(Detail);
            //--------------------------------------------------
            var allEstablishment = new EstablishmentService().GetEstablishments();
            var allStores        = allEstablishment.Where(e => e.Type == _establishmenType).ToList();

            Establishments    = allStores;
            _allEstablishment = allStores;
        }
Exemplo n.º 12
0
        public ActionResult AcademicYear(EstablishmentType estab)
        {
            ViewBag.Estab = estab;

            switch (estab)
            {
            case EstablishmentType.Academies:
            case EstablishmentType.MAT:
                ViewBag.Terms = _dataService.GetActiveTermsForAcademiesAsync();
                break;

            default:
                ViewBag.Terms = _dataService.GetActiveTermsForMaintainedAsync();
                break;
            }

            return(View("AcademicYear"));
        }
Exemplo n.º 13
0
        public static string ToDataGroup(this EstablishmentType estabType)
        {
            switch (estabType)
            {
            case EstablishmentType.Academies:
                return(DataGroups.Academies);

            case EstablishmentType.Federation:
            case EstablishmentType.Maintained:
                return(DataGroups.Maintained);

            case EstablishmentType.MAT:
                return(DataGroups.MATCentral);

            default:
                return(null);
            }
        }
        /// <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"));
            }
        }
        //public async Task<IEnumerable<SchoolTrustFinancialDataObject>> GetTrustFinancialDataObjectAsync(int companyNo, string term, MatFinancingType matFinance)
        //{
        //    var dataGroup = EstablishmentType.MAT.ToDataGroup(matFinance);

        //    var collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, dataGroup);

        //    var query = $"SELECT * FROM c WHERE c['{SchoolTrustFinanceDataFieldNames.COMPANY_NUMBER}']=@companyNo";
        //    SqlQuerySpec querySpec = new SqlQuerySpec(query);
        //    querySpec.Parameters = new SqlParameterCollection();
        //    querySpec.Parameters.Add(new SqlParameter($"@companyNo", companyNo));

        //    try
        //    {
        //        var documentQuery =
        //            _client.CreateDocumentQuery<SchoolTrustFinancialDataObject>(
        //                UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionName),
        //                querySpec);

        //        return await documentQuery.QueryAsync();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (term.Contains(_dataCollectionManager.GetLatestFinancialDataYearPerEstabTypeAsync(EstablishmentType.MAT).ToString()))
        //        {
        //            var errorMessage = $"{collectionName} could not be loaded! : {ex.Message} : {querySpec.Parameters[0].Name} = {querySpec.Parameters[0].Value}";
        //            base.LogException(ex, errorMessage);
        //        }
        //        return null;
        //    }
        //}

        public async Task <List <SchoolTrustFinancialDataObject> > SearchSchoolsByCriteriaAsync(
            BenchmarkCriteria criteria,
            EstablishmentType estType,
            bool excludePartial = false,
            bool excludeFeds    = true)
        {
            if (estType == EstablishmentType.All)
            {
                var maintainedSchoolsTask = QueryDBSchoolCollectionAsync(criteria, DataGroups.Maintained, excludePartial, excludeFeds);
                var academiesTask         = QueryDBSchoolCollectionAsync(criteria, DataGroups.Academies, excludePartial, excludeFeds);
                var maintainedSchools     = (await maintainedSchoolsTask).ToList();
                var academies             = (await academiesTask).ToList();
                maintainedSchools.AddRange(academies);
                return(maintainedSchools);
            }
            else
            {
                return((await QueryDBSchoolCollectionAsync(criteria, estType.ToDataGroup(), excludePartial, excludeFeds)).ToList());
            }
        }
Exemplo n.º 16
0
        public async Task <ActionResult> Download(EstablishmentType type)
        {
            List <ChartViewModel> benchmarkCharts;
            string csv = null;

            if (type == EstablishmentType.MAT)
            {
                benchmarkCharts = BuildTrustBenchmarkCharts(RevenueGroupType.AllExcludingSchoolPerf, ChartGroupType.All, UnitType.AbsoluteMoney, MatFinancingType.TrustAndAcademies);
                csv             = _csvBuilder.BuildCSVContentForTrusts(base.ExtractTrustComparisonListFromCookie(), benchmarkCharts);
            }
            else
            {
                benchmarkCharts = await BuildSchoolBenchmarkChartsAsync(RevenueGroupType.AllIncludingSchoolPerf, ChartGroupType.All, null, CentralFinancingType.Exclude);

                csv = _csvBuilder.BuildCSVContentForSchools(base.ExtractSchoolComparisonListFromCookie(), benchmarkCharts);
            }

            return(File(Encoding.UTF8.GetBytes(csv),
                        "text/plain",
                        "BenchmarkData.csv"));
        }
Exemplo n.º 17
0
        public static string ToDataGroup(this EstablishmentType estabType, MatFinancingType mFinance)
        {
            switch (estabType)
            {
            case EstablishmentType.MAT:
                switch (mFinance)
                {
                case MatFinancingType.TrustOnly:
                    return(DataGroups.MATCentral);

                case MatFinancingType.TrustAndAcademies:
                    return(DataGroups.MATOverview);

                case MatFinancingType.AcademiesOnly:
                    return(DataGroups.MATTotals);

                default:
                    return(DataGroups.MATCentral);
                }

            default:
                return(estabType.ToDataGroup());
            }
        }
        public async Task <int> GetEstablishmentRecordCountAsync(string term, EstablishmentType estType)
        {
            var collectionName = string.Empty;

            switch (estType)
            {
            case EstablishmentType.Academy:
                collectionName = _dataCollectionManager.GetCollectionIdByTermByDataGroup(term, "MAT-Distributed");
                break;

            case EstablishmentType.Maintained:
                collectionName = _dataCollectionManager.GetCollectionIdByTermByDataGroup(term, "Maintained");
                break;

            case EstablishmentType.MAT:
                collectionName = _dataCollectionManager.GetCollectionIdByTermByDataGroup(term, "MAT-Overview");
                break;
            }

            var result =
                _client.CreateDocumentQuery <int>(UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionName), $"SELECT VALUE COUNT(c) FROM c");

            return((await result.QueryAsync()).First());
        }
Exemplo n.º 19
0
        public async Task <PartialViewResult> GetCharts(RevenueGroupType revGroup, ChartGroupType chartGroup, UnitType showValue, CentralFinancingType centralFinancing = CentralFinancingType.Include, MatFinancingType trustCentralFinancing = MatFinancingType.TrustAndAcademies, EstablishmentType type = EstablishmentType.All, ChartFormat format = ChartFormat.Charts)
        {
            List <ChartViewModel> benchmarkCharts;

            if (type == EstablishmentType.MAT)
            {
                benchmarkCharts      = BuildTrustBenchmarkCharts(revGroup, chartGroup, showValue, trustCentralFinancing);
                ViewBag.HomeSchoolId = this.ExtractTrustComparisonListFromCookie().DefaultTrustMatNo;
            }
            else
            {
                benchmarkCharts = await BuildSchoolBenchmarkChartsAsync(revGroup, chartGroup, showValue, centralFinancing);

                ViewBag.HomeSchoolId = this.ExtractSchoolComparisonListFromCookie().HomeSchoolUrn;
            }

            ViewBag.EstablishmentType = type;
            ViewBag.ChartFormat       = format;

            return(PartialView("Partials/Chart", benchmarkCharts));
        }
Exemplo n.º 20
0
        public async Task <PartialViewResult> TabChange(EstablishmentType type, UnitType showValue, RevenueGroupType tab = RevenueGroupType.Expenditure, CentralFinancingType financing = CentralFinancingType.Include, MatFinancingType trustFinancing = MatFinancingType.TrustAndAcademies, ChartFormat format = ChartFormat.Charts)
        {
            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;
            }

            UnitType unitType;

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

            case RevenueGroupType.Balance:
                unitType = showValue == UnitType.AbsoluteMoney || showValue == UnitType.PerPupil || showValue == UnitType.PerTeacher ? showValue : UnitType.AbsoluteMoney;
                break;

            default:
                unitType = showValue;
                break;
            }

            List <ChartViewModel> benchmarkCharts;

            if (type == EstablishmentType.MAT)
            {
                benchmarkCharts = BuildTrustBenchmarkCharts(tab, chartGroup, unitType, trustFinancing);
            }
            else
            {
                benchmarkCharts = await BuildSchoolBenchmarkChartsAsync(tab, chartGroup, unitType, financing);
            }
            var chartGroups = _benchmarkChartBuilder.Build(tab, EstablishmentType.All).DistinctBy(c => c.ChartGroup).ToList();

            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.Manual, null, null, null, type, type, null, null, academiesTerm, maintainedTerm, ComparisonArea.All, null, null, ComparisonListLimit.DEFAULT, base.ExtractTrustComparisonListFromCookie());

            ViewBag.Tab               = tab;
            ViewBag.ChartGroup        = chartGroup;
            ViewBag.UnitType          = unitType;
            ViewBag.EstablishmentType = type;
            ViewBag.Financing         = financing;
            ViewBag.TrustFinancing    = trustFinancing;
            ViewBag.HomeSchoolId      = (type == EstablishmentType.MAT) ? vm.TrustComparisonList.DefaultTrustMatNo : vm.SchoolComparisonList.HomeSchoolUrn;
            ViewBag.ChartFormat       = format;

            return(PartialView("Partials/TabContent", vm));
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
0
 public StoresViewModel(EstablishmentType establishmentType) : base(establishmentType)
 {
 }
Exemplo n.º 23
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"));
            }
        }
        private void BuildHeaderLine(List <ChartViewModel> benchmarkCharts, StringBuilder csv, EstablishmentType establishmentType)
        {
            var header = new StringBuilder();

            header.Append(establishmentType == EstablishmentType.MAT ? "Trust Name" : "School Name");
            header.Append(",URN,Analysis Period,Number of Pupils,Number of Teachers,");
            foreach (var chart in benchmarkCharts.Where(bc => bc.Downloadable))
            {
                header.Append(chart.Name);
                header.Append(",");
            }

            foreach (var col in benchmarkCharts.Where(bc => bc.TableColumns != null).SelectMany(bc => bc.TableColumns))
            {
                header.Append(col.Name);
                header.Append(",");
            }
            csv.AppendLine(header.ToString().TrimEnd(','));
        }
Exemplo n.º 25
0
        public async Task <ActionResult> GenerateFromSimpleCriteria(string urn, int basketSize, EstablishmentType estType, SimpleCriteria simpleCriteria)
        {
            var benchmarkSchool = InstantiateBenchmarkSchool(urn);

            var benchmarkCriteria = _benchmarkCriteriaBuilderService.BuildFromSimpleComparisonCriteria(benchmarkSchool.LatestYearFinancialData, simpleCriteria);

            var comparisonResult = await _comparisonService.GenerateBenchmarkListWithSimpleComparisonAsync(benchmarkCriteria, estType, basketSize, simpleCriteria, benchmarkSchool.LatestYearFinancialData);

            var benchmarkSchools = comparisonResult.BenchmarkSchools;

            benchmarkCriteria = comparisonResult.BenchmarkCriteria;

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

            Response.Cookies.Add(cookie);

            foreach (var schoolDoc in 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);
            }

            AddDefaultBenchmarkSchoolToList();

            return(await Index(urn, simpleCriteria, benchmarkCriteria, basketSize, benchmarkSchool.LatestYearFinancialData, estType, ComparisonType.Basic));
        }
Exemplo n.º 26
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));
        }
Exemplo n.º 27
0
 public EstablishmentTypeView(EstablishmentType entity)
 {
     Id          = entity.RevisionId;
     EnglishName = entity.EnglishName;
 }
Exemplo n.º 28
0
        public async Task <int> GenerateCountFromAdvancedCriteria(BenchmarkCriteriaVM criteria, EstablishmentType estType, int?lacode, bool excludePartial = false)
        {
            if (!ModelState.IsValid)
            {
                return(0);
            }

            if (criteria.AdvancedCriteria == null)
            {
                criteria.AdvancedCriteria = new BenchmarkCriteria();
            }
            criteria.AdvancedCriteria.LocalAuthorityCode = lacode;
            var result = await _financialDataService.SearchSchoolsCountByCriteriaAsync(criteria.AdvancedCriteria, estType, excludePartial);

            return(result);
        }
Exemplo n.º 29
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 object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            EstablishmentType type = (EstablishmentType)value;

            return((type == EstablishmentType.Store) ? "Loja" : "Restaurante");
        }
Exemplo n.º 31
0
 public EstablishmentTypeView(EstablishmentType entity)
 {
     Id = entity.RevisionId;
     EnglishName = entity.EnglishName;
 }