/// <summary>
        /// Get school data to use for search autocomplete functionality
        /// </summary>
        /// <returns>
        /// List of autcomplete data to use for search autocomplete functionality
        /// </returns>
        public async Task <IEnumerable <AutocompleteViewModel> > Get()
        {
            _logger.LogInformation("Executing Get method in AutoCompleteService class.");

            //Get data if the _schools list is empty
            if (_schools.Count() == 0)
            {
                //Attempt to get data from cache first
                var cacheData = await _cache.GetAutoCompleteData();

                //Get data from database if it is not in cache
                if (cacheData.Count() == 0)
                {
                    _logger.LogInformation("Autocomplete data is being retrieved from the database");

                    var schoolLst = await _result.GetAll(r => r.School);

                    _schools = schoolLst.ConvertToAutocompleteViewModel();

                    //Save data to cache for future use
                    await _cache.SaveAutoCompleteData(_schools);
                }
                else
                {
                    _schools = cacheData;
                }
            }

            return(_schools);
        }
        public async Task GetAllRecordsFromADbsetExcludingNational()
        {
            //Act
            var schoolLst = await _repositorySchool.GetAll();

            //Assert
            Assert.AreEqual(
                _schools.Where(s => s.URN != 9).Count(),
                schoolLst.Count()
                );

            //Act
            schoolLst = await _repositorySchool.GetAll();

            //Assert
            Assert.AreEqual(
                _schools.Where(s => s.URN != 9).Count(),
                schoolLst.Count()
                );
        }
示例#3
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));
        }