Exemplo n.º 1
0
        private HttpCookie RemoveSchoolFromCookie(BenchmarkSchoolModel benchmarkSchool, string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];

            if (cookie != null)
            {
                var listCookie = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                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, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }

            return(cookie);
        }
Exemplo n.º 2
0
 public void TryAddSchoolToBenchmarkList(BenchmarkSchoolModel bmSchool)
 {
     try
     {
         UpdateSchoolComparisonListCookie(CookieActions.Add, bmSchool);
     }
     catch (ApplicationException) { }//ignore duplicate add
 }
Exemplo n.º 3
0
        public async Task SetSchoolAsDefaultAsync(long urn)
        {
            var benchmarkSchoolDataObject = await _contextDataService.GetSchoolDataObjectByUrnAsync(urn);

            var defaultBenchmarkSchool = new BenchmarkSchoolModel(benchmarkSchoolDataObject);

            try
            {
                AddSchoolToBenchmarkList(defaultBenchmarkSchool);
            }
            catch { }
            UpdateSchoolComparisonListCookie(CookieActions.SetDefault, defaultBenchmarkSchool);
        }
Exemplo n.º 4
0
        public async Task AddSchoolsToBenchmarkListAsync(ComparisonType comparison, List <long> urnList)
        {
            var benchmarkSchoolDataObjects = await _contextDataService.GetMultipleSchoolDataObjectsByUrnsAsync(urnList);

            foreach (var schoolContextData in benchmarkSchoolDataObjects)
            {
                var benchmarkSchoolToAdd = new BenchmarkSchoolModel(schoolContextData);

                if (comparison == ComparisonType.BestInClass)
                {
                    var schoolFinancialData = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(long.Parse(benchmarkSchoolToAdd.Urn), (EstablishmentType)Enum.Parse(typeof(EstablishmentType), benchmarkSchoolToAdd.EstabType));

                    benchmarkSchoolToAdd.ProgressScore = schoolFinancialData.ProgressScore;
                }
                TryAddSchoolToBenchmarkList(benchmarkSchoolToAdd);
            }
        }
Exemplo n.º 5
0
        private HttpCookie AddSchoolToCookie(BenchmarkSchoolModel benchmarkSchool, string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];

            if (cookie == null)
            {
                cookie = new HttpCookie(cookieName);
                var listCookie = new SchoolComparisonListModel();
                listCookie.BenchmarkSchools = new List <BenchmarkSchoolModel>()
                {
                    benchmarkSchool
                };
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            else
            {
                var listCookie = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                if (listCookie.BenchmarkSchools.Any(s => s.Id == benchmarkSchool.Id))
                {
                    throw new ApplicationException(ErrorMessages.DuplicateSchool);
                }
                if (listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT || listCookie.HomeSchoolUrn == benchmarkSchool.Urn)
                {
                    if (listCookie.BenchmarkSchools.Any(s => s.Name == benchmarkSchool.Name))
                    {
                        benchmarkSchool.Name += " ";
                    }

                    listCookie.BenchmarkSchools.Add(benchmarkSchool);
                }
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }

            cookie.HttpOnly = false;
            cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
            return(cookie);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Index()
        {
            var comparisonList = _benchmarkBasketService.GetSchoolBenchmarkList();

            var benchmarkSchoolDataObjects = await _contextDataService.GetMultipleSchoolDataObjectsByUrnsAsync(comparisonList.BenchmarkSchools.Select(b => long.Parse(b.Urn)).ToList());

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

            if (benchmarkSchoolDataObjects != null)
            {
                foreach (var benchmarkSchoolDataObject in benchmarkSchoolDataObjects)
                {
                    BenchmarkSchoolModel benchmarkSchool;

                    if (benchmarkSchoolDataObject.IsFederation)
                    {
                        var federation         = new FederationViewModel(benchmarkSchoolDataObject);
                        var financialDataModel = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(federation.Id, federation.EstablishmentType);

                        benchmarkSchool = new BenchmarkSchoolModel(federation)
                        {
                            IsReturnsComplete    = financialDataModel.IsReturnsComplete,
                            WorkforceDataPresent = financialDataModel.WorkforceDataPresent
                        };
                    }
                    else
                    {
                        var school             = new SchoolViewModel(benchmarkSchoolDataObject);
                        var financialDataModel = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(school.Id, school.EstablishmentType);

                        benchmarkSchool = new BenchmarkSchoolModel(school)
                        {
                            Address              = school.Address,
                            IsReturnsComplete    = financialDataModel.IsReturnsComplete,
                            WorkforceDataPresent = financialDataModel.WorkforceDataPresent
                        };
                    }

                    comparisonList.BenchmarkSchools.Add(benchmarkSchool);
                }
            }

            comparisonList.BenchmarkSchools = comparisonList.BenchmarkSchools.OrderBy(s => SanitizeSchoolName(s.Name)).ToList();

            return(View(comparisonList));
        }
Exemplo n.º 7
0
        private HttpCookie SetDefaultSchoolInCookie(BenchmarkSchoolModel benchmarkSchool, string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];

            if (cookie == null)
            {
                cookie = new HttpCookie(cookieName);
                var listCookie = new SchoolComparisonListModel();
                listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                listCookie.HomeSchoolName          = benchmarkSchool.Name;
                listCookie.HomeSchoolType          = benchmarkSchool.Type;
                listCookie.HomeSchoolFinancialType = benchmarkSchool.EstabType;
                listCookie.BenchmarkSchools        = new List <BenchmarkSchoolModel>()
                {
                    benchmarkSchool
                };
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }
            else
            {
                var listCookie = JsonConvert.DeserializeObject <SchoolComparisonListModel>(cookie.Value, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
                listCookie.HomeSchoolUrn           = benchmarkSchool.Urn;
                listCookie.HomeSchoolName          = benchmarkSchool.Name;
                listCookie.HomeSchoolType          = benchmarkSchool.Type;
                listCookie.HomeSchoolFinancialType = benchmarkSchool.EstabType;
                if (benchmarkSchool.Urn != null && listCookie.BenchmarkSchools.Count < ComparisonListLimit.LIMIT && listCookie.BenchmarkSchools.All(s => s.Urn != benchmarkSchool.Urn))
                {
                    listCookie.BenchmarkSchools.Add(benchmarkSchool);
                }
                cookie.Value = JsonConvert.SerializeObject(listCookie, new JsonSerializerSettings()
                {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii, Culture = new CultureInfo("en-GB", true)
                });
            }

            cookie.HttpOnly = false;
            cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
            return(cookie);
        }
Exemplo n.º 8
0
        public void UpdateManualComparisonListCookie(CookieActions withAction, BenchmarkSchoolModel benchmarkSchool = null)
        {
            HttpCookie cookie = null;

            switch (withAction)
            {
            case CookieActions.Add:
                cookie = AddSchoolToCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL);
                break;

            case CookieActions.Remove:
                cookie = RemoveSchoolFromCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL);
                break;

            case CookieActions.SetDefault:
                cookie = SetDefaultSchoolInCookie(benchmarkSchool, CookieNames.COMPARISON_LIST_MANUAL);
                break;

            case CookieActions.UnsetDefault:
                cookie = UnsetDefaultSchoolInCookie(CookieNames.COMPARISON_LIST_MANUAL);
                break;

            case CookieActions.RemoveAll:
                cookie = RemoveAllSchoolsFromCookie(CookieNames.COMPARISON_LIST_MANUAL);
                break;

            case CookieActions.AddDefaultToList:
                cookie = AddDefaultSchoolToListInCookie(CookieNames.COMPARISON_LIST_MANUAL);
                break;
            }

            if (cookie != null)
            {
                cookie.HttpOnly = false;
                cookie.Secure   = HttpContext.Current.Request.IsSecureConnection;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        }
Exemplo n.º 9
0
        public void UpdateSchoolComparisonListCookie(CookieActions withAction, BenchmarkSchoolModel benchmarkSchool = null)
        {
            HttpCookie cookie = null;

            switch (withAction)
            {
            case CookieActions.Add:
                cookie = AddSchoolToCookie(benchmarkSchool, CookieNames.COMPARISON_LIST);
                break;

            case CookieActions.Remove:
                cookie = RemoveSchoolFromCookie(benchmarkSchool, CookieNames.COMPARISON_LIST);
                break;

            case CookieActions.SetDefault:
                cookie = SetDefaultSchoolInCookie(benchmarkSchool, CookieNames.COMPARISON_LIST);
                break;

            case CookieActions.UnsetDefault:
                cookie = UnsetDefaultSchoolInCookie(CookieNames.COMPARISON_LIST);
                break;

            case CookieActions.RemoveAll:
                cookie = RemoveAllSchoolsFromCookie(CookieNames.COMPARISON_LIST);
                break;

            case CookieActions.AddDefaultToList:
                cookie = AddDefaultSchoolToListInCookie(CookieNames.COMPARISON_LIST);
                break;
            }

            if (cookie != null)
            {
                cookie.Expires = DateTime.MaxValue;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        }
Exemplo n.º 10
0
 public void AddSchoolToBenchmarkList(BenchmarkSchoolModel bmSchool)
 {
     UpdateSchoolComparisonListCookie(CookieActions.Add, bmSchool);
 }
Exemplo n.º 11
0
 public void SetSchoolAsDefault(BenchmarkSchoolModel benchmarkSchool)
 {
     UpdateSchoolComparisonListCookie(CookieActions.SetDefault, benchmarkSchool);
 }
Exemplo n.º 12
0
        public async Task <ActionResult> ReplaceAdd(BenchmarkListOverwriteStrategy?overwriteStrategy, string referrer)
        {
            var comparisonList       = _schoolBenchmarkListService.GetSchoolBenchmarkList();
            var manualComparisonList = _manualBenchmarkListService.GetManualBenchmarkList();

            switch (overwriteStrategy)
            {
            case null:
                SchoolViewModel vm = null;
                if (comparisonList.HomeSchoolUrn == null)
                {
                    vm = new SchoolViewModelWithNoDefaultSchool(comparisonList, manualComparisonList);
                }
                else
                {
                    var contextDataObject = await _contextDataService.GetSchoolDataObjectByUrnAsync(long.Parse(comparisonList.HomeSchoolUrn));

                    vm = new SchoolViewModel(contextDataObject, comparisonList, manualComparisonList);
                }

                vm.ErrorMessage  = ErrorMessages.SelectOverwriteStrategy;
                ViewBag.referrer = referrer;
                return(View("OverwriteStrategy", vm));

            case BenchmarkListOverwriteStrategy.Add:
                if (comparisonList.BenchmarkSchools.Count + manualComparisonList.BenchmarkSchools.Where(s => s.Urn != manualComparisonList.HomeSchoolUrn).Count() > ComparisonListLimit.LIMIT)
                {
                    if (comparisonList.HomeSchoolUrn == null)
                    {
                        vm = new SchoolViewModelWithNoDefaultSchool(comparisonList, manualComparisonList);
                    }
                    else
                    {
                        var contextDataObject = await _contextDataService.GetSchoolDataObjectByUrnAsync(long.Parse(comparisonList.HomeSchoolUrn));

                        vm = new SchoolViewModel(contextDataObject, comparisonList, manualComparisonList);
                    }

                    vm.ErrorMessage  = ErrorMessages.BMBasketLimitExceed;
                    ViewBag.referrer = referrer;
                    return(View("OverwriteStrategy", vm));
                }
                else
                {
                    foreach (var school in manualComparisonList.BenchmarkSchools.Where(s => s.Urn != manualComparisonList.HomeSchoolUrn))
                    {
                        _schoolBenchmarkListService.TryAddSchoolToBenchmarkList(school);
                    }
                    return(Redirect("/BenchmarkCharts"));
                }

            case BenchmarkListOverwriteStrategy.Overwrite:
            default:
                _schoolBenchmarkListService.ClearSchoolBenchmarkList();
                foreach (var school in manualComparisonList.BenchmarkSchools.Where(s => s.Urn != manualComparisonList.HomeSchoolUrn))
                {
                    _schoolBenchmarkListService.AddSchoolToBenchmarkList(school);
                }
                var benchmarkSchool = new BenchmarkSchoolModel(manualComparisonList);

                _schoolBenchmarkListService.SetSchoolAsDefault(benchmarkSchool);
                return(Redirect("/BenchmarkCharts"));
            }
        }