Exemple #1
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));
        }
Exemple #2
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()));
        }
Exemple #3
0
        private void AddDefaultBenchmarkSchoolToList()
        {
            var cookieObject           = ExtractSchoolComparisonListFromCookie();
            var defaultBenchmarkSchool = new BenchmarkSchoolViewModel()
            {
                Name          = cookieObject.HomeSchoolName,
                Type          = cookieObject.HomeSchoolType,
                FinancialType = cookieObject.HomeSchoolFinancialType,
                Urn           = cookieObject.HomeSchoolUrn
            };
            var cookie = base.UpdateSchoolComparisonListCookie(CompareActions.ADD_TO_COMPARISON_LIST, defaultBenchmarkSchool);

            Response.Cookies.Add(cookie);
        }
        public ActionResult Index()
        {
            var comparisonList = base.ExtractSchoolComparisonListFromCookie();

            if (comparisonList.BenchmarkSchools.Count > 1)
            {
                dynamic dynamicBenchmarkSchools = _contextDataService.GetMultipleSchoolsByUrns(comparisonList.BenchmarkSchools.Select(b => b.Urn.ToString()).ToList());

                comparisonList.BenchmarkSchools = new List <BenchmarkSchoolViewModel>();

                foreach (var dynamicBenchmarkSchool in dynamicBenchmarkSchools)
                {
                    var school          = new SchoolViewModel(dynamicBenchmarkSchool);
                    var benchmarkSchool = new BenchmarkSchoolViewModel()
                    {
                        Address       = school.Address,
                        Name          = school.Name,
                        Phase         = school.OverallPhase,
                        Type          = school.Type,
                        FinancialType = school.FinancialType.ToString(),
                        Urn           = school.Id
                    };

                    comparisonList.BenchmarkSchools.Add(benchmarkSchool);
                }
            }
            else if (comparisonList.BenchmarkSchools.Count == 1)
            {
                var dynamicBenchmarkSchool = _contextDataService.GetSchoolByUrn(comparisonList.BenchmarkSchools[0].Urn);

                comparisonList.BenchmarkSchools = new List <BenchmarkSchoolViewModel>();

                var school          = new SchoolViewModel(dynamicBenchmarkSchool);
                var benchmarkSchool = new BenchmarkSchoolViewModel()
                {
                    Address       = school.Address,
                    Name          = school.Name,
                    Phase         = school.OverallPhase,
                    Type          = school.Type,
                    FinancialType = school.FinancialType.ToString(),
                    Urn           = school.Id
                };

                comparisonList.BenchmarkSchools.Add(benchmarkSchool);
            }

            return(View(comparisonList));
        }
        public HttpCookie UpdateSchoolComparisonListCookie(string withAction, BenchmarkSchoolViewModel benchmarkSchool)
        {
            HttpCookie cookie = null;

            switch (withAction)
            {
            case CompareActions.ADD_TO_COMPARISON_LIST:
                cookie = Request.Cookies[CookieNames.COMPARISON_LIST];
                if (cookie == null)
                {
                    cookie = new HttpCookie(CookieNames.COMPARISON_LIST);
                    var listCookie = new ComparisonListModel();
                    listCookie.BenchmarkSchools = new List <BenchmarkSchoolViewModel>()
                    {
                        benchmarkSchool
                    };
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                else
                {
                    var listCookie = JsonConvert.DeserializeObject <ComparisonListModel>(cookie.Value);
                    if ((listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT || listCookie.HomeSchoolUrn == benchmarkSchool.Urn) && !listCookie.BenchmarkSchools.Any(s => s.Urn == benchmarkSchool.Urn))
                    {
                        listCookie.BenchmarkSchools.Add(benchmarkSchool);
                    }
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                break;

            case CompareActions.REMOVE_FROM_COMPARISON_LIST:
                cookie = Request.Cookies[CookieNames.COMPARISON_LIST];
                if (cookie != null)
                {
                    var listCookie = JsonConvert.DeserializeObject <ComparisonListModel>(cookie.Value);
                    listCookie.BenchmarkSchools.Remove(benchmarkSchool);
                    if (listCookie.HomeSchoolUrn == benchmarkSchool.Urn)
                    {
                        listCookie.HomeSchoolUrn           = null;
                        listCookie.HomeSchoolName          = null;
                        listCookie.HomeSchoolType          = null;
                        listCookie.HomeSchoolFinancialType = null;
                    }
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                break;

            case CompareActions.MAKE_DEFAULT_BENCHMARK:
                cookie = Request.Cookies[CookieNames.COMPARISON_LIST];
                if (cookie == null)
                {
                    cookie = new HttpCookie(CookieNames.COMPARISON_LIST);
                    var listCookie = new ComparisonListModel();
                    listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                    listCookie.HomeSchoolName          = benchmarkSchool.Name;
                    listCookie.HomeSchoolType          = benchmarkSchool.Type;
                    listCookie.HomeSchoolFinancialType = benchmarkSchool.FinancialType;
                    listCookie.BenchmarkSchools        = new List <BenchmarkSchoolViewModel>()
                    {
                        benchmarkSchool
                    };
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                else
                {
                    var listCookie = JsonConvert.DeserializeObject <ComparisonListModel>(cookie.Value);
                    listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                    listCookie.HomeSchoolName          = benchmarkSchool.Name;
                    listCookie.HomeSchoolType          = benchmarkSchool.Type;
                    listCookie.HomeSchoolFinancialType = benchmarkSchool.FinancialType;
                    if (listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT && listCookie.BenchmarkSchools.All(s => s.Urn != benchmarkSchool.Urn))
                    {
                        listCookie.BenchmarkSchools.Add(benchmarkSchool);
                    }
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                break;

            case CompareActions.REMOVE_DEFAULT_BENCHMARK:
                cookie = Request.Cookies[CookieNames.COMPARISON_LIST];
                if (cookie != null)
                {
                    var listCookie = JsonConvert.DeserializeObject <ComparisonListModel>(cookie.Value);
                    listCookie.HomeSchoolUrn           = null;
                    listCookie.HomeSchoolName          = null;
                    listCookie.HomeSchoolType          = null;
                    listCookie.HomeSchoolFinancialType = null;
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                break;

            case CompareActions.CLEAR_BENCHMARK_LIST:
                cookie = Request.Cookies[CookieNames.COMPARISON_LIST];
                if (cookie != null)
                {
                    var listCookie = JsonConvert.DeserializeObject <ComparisonListModel>(cookie.Value);
                    listCookie.BenchmarkSchools = new List <BenchmarkSchoolViewModel>();
                    cookie.Value = JsonConvert.SerializeObject(listCookie);
                }
                break;
            }

            if (cookie != null)
            {
                cookie.Expires = DateTime.MaxValue;
            }
            return(cookie);
        }