コード例 #1
0
        public async Task <IActionResult> GetResultsAll()
        {
            _logger.LogInformation("Request made to get JSON object with data for Table All page");

            //Check if data is in cache
            var resultViewModel = await _cache.GetTableDataAll();

            //Get results for all schools from database if data is not in cache
            if (resultViewModel.Count() == 0)
            {
                _logger.LogInformation("Table all data is being retrieved from the database");

                var result = await _result.GetAll(r => r.OrderBy(s => s.School.SCHNAME), r => r.School);

                //Converts from list of SchoolResult to List of TableViewModel
                resultViewModel = result.ConvertToTableViewModelAll();

                //Save list of TableViewModel data to cache
                await _cache.SaveTableDataAll(resultViewModel);
            }

            //Check if data is in cache
            var resultNatViewModel = await _cache.GetNationalTableDataAll();

            //Get the national data from database if data is not in cache
            if (resultNatViewModel == null)
            {
                _logger.LogInformation("Table national all data is being retrieved from the database");

                var nationalResultLst = await _result.GetNational();

                //Because there is only currently national data for 2019 there should only be 1 result
                var nationalResult = nationalResultLst.First();

                //Convert national SchoolResult object to a TableViewModel object
                resultNatViewModel = nationalResult;

                //Save National TableViewModel data to cache
                await _cache.SaveNationalTableDataAll(resultNatViewModel);
            }


            var data = new { data = resultViewModel, national = resultNatViewModel };

            return(Json(data));
        }
コード例 #2
0
        public async Task GetNationalData()
        {
            //Act
            var national = await _repositorySchool.GetNational();

            var nationalResult = await _repositorySchoolResult.GetNational();

            //Assert
            Assert.AreEqual(
                _schools.Where(x => x.URN == 9).Count(),
                national.Count());


            //Assert
            Assert.AreEqual(
                _schoolResults.Where(x => x.URN == 9).Count(),
                nationalResult.Count());
        }
コード例 #3
0
        public async Task <IActionResult> Index()
        {
            _logger.LogInformation("Request made to view Scatterplot page");

            //Check if data is in cache and if so get the data from cache
            IEnumerable <ScatterplotViewModel> schoolLst = await _cache.GetScatterplotData();

            ScatterplotViewModel national = await _cache.GetNationalScatterplotData();

            //if data is not in cache get data from database and save data in cache
            if (schoolLst.Count() == 0)
            {
                _logger.LogInformation("Scatterplot data is being retrieved from the database");

                var result = await _result.Get(r => r.PTFSM6CLA1A != null,
                                               r => r.OrderBy(s => s.School.SCHNAME),
                                               r => r.School);

                //Converts from list of SchoolResult to List of ScatterplotViewModel
                schoolLst = result.ConvertToScatterplotViewModel();

                await _cache.SaveScatterplotData(schoolLst);
            }

            //if national data is not in cache get data from database and save data in cache
            if (national == null)
            {
                _logger.LogInformation("National Scatterplot data is being retrieved from the database");

                var result = await _result.GetNational(r => r.School);

                national = result.First();

                await _cache.SaveNationalScatterplotData(national);
            }

            var resultViewModel = new ScatterplotListViewModel()
            {
                schoolData   = schoolLst,
                nationalData = national,
            };

            return(View(resultViewModel));
        }
コード例 #4
0
        public async Task <IActionResult> Index(int id)
        {
            _logger.LogInformation($"Request made to view School page with id: {id}");

            _logger.LogInformation($"Data for {id} is being retrieved from the database");

            //Get the school data for the 2019 academic year
            var schoolResult = await _result
                               .GetByUrnOrLAESATB(id, s => s.ACADEMICYEAR == 2019, s => s.School);

            var schoolContextual = await _contextual
                                   .GetByUrnOrLAESATB(id, s => s.ACADEMICYEAR == 2019);

            //Return a page letting the user know the id cannot be found
            //If the school id does not exist
            if (schoolResult.Count() == 0)
            {
                return(View("SchoolNotFound", id));
            }

            _logger.LogInformation($"National data is being retrieved from the database");

            //Get the national data
            var nationalResult = await _result.GetNational(s => s.ACADEMICYEAR == 2019, s => s.School);

            var nationalContextual = await _contextual.GetNational(s => s.ACADEMICYEAR == 2019);

            //Add School and National data to the SchoolViewModel
            var schoolViewModel = new SchoolViewModel()
            {
                ResultSchool       = schoolResult.First(),
                ResultNational     = nationalResult.First(),
                ContextualSchool   = schoolContextual.First(),
                ContextualNational = nationalContextual.First()
            };

            return(View(schoolViewModel));
        }