Example #1
0
        /// <summary>
        ///     Sustituye los placeholders marcados entre corchetes "{" "}" especificados en el fichero "appsettings.json"
        ///     en el apartado "Covid19Api" por los datos filtrados en la vista-modelo recogidas en el formulario de búsqueda
        /// </summary>
        /// <param name="byCountryStatusViewModel">La vista-modelo que contienen las opciones seleccionadas en el
        /// formulario de búsqueda</param>
        /// <returns>La URL de la API "live/country/status" con los parámetros de búsqueda sustituídos</returns>
        private string ExtractPlaceholderUrlApi(LiveByCountryAndStatusViewModel byCountryStatusViewModel)
        {
            string byCountryStatusApiUrl = GetAppSettingsUrlApiByKey(AppSettingsConfig.LIVE_BY_CONTRY_AND_STATUS_KEY);

            byCountryStatusViewModel.Country ??= "Spain";
            byCountryStatusViewModel.StatusType ??= "confirmed";

            return(new StringBuilder(byCountryStatusApiUrl)
                   .Replace(AppSettingsConfig.COUNTRYNAME_PLACEHOLDER, byCountryStatusViewModel.Country)
                   .Replace(AppSettingsConfig.STATUS_PLACEHOLDER, byCountryStatusViewModel.StatusType)
                   .ToString());
        }
Example #2
0
        /// <summary>
        ///     Aplica el filtro de búsqueda para los datos en directo de los países y sus estados
        /// </summary>
        /// <param name="byCountryStatusUrlList">La lista de países</param>
        /// <param name="byCountryStatusViewModel">La vista-modelo que contienen las opciones seleccionadas en el formulario de búsqueda</param>
        /// <returns>Lista con los datos en directo de los países, ordenadas de fechas más recientes a más antiguas</returns>
        private IEnumerable <LiveByCountryAndStatus> ApplySearchFilter(IEnumerable <LiveByCountryAndStatus> byCountryStatusUrlList,
                                                                       LiveByCountryAndStatusViewModel byCountryStatusViewModel)
        {
            if (byCountryStatusViewModel.Country == null)
            {
                return(byCountryStatusUrlList.OrderByDescending(bc => bc.Date.Date));
            }

            return(byCountryStatusUrlList
                   .Where(live => live.Country.Equals(byCountryStatusViewModel.Country))
                   .OrderByDescending(live => live.Date.Date));
        }
Example #3
0
        public async Task <ActionResult <IEnumerable <LiveByCountryAndStatus> > > GetLiveByCountryAndStatus(
            LiveByCountryAndStatusViewModel byCountryStatusViewModel)
        {
            if (ModelState.IsValid)
            {
                byCountryStatusCacheKey = $"{byCountryStatusCacheKey}_{byCountryStatusViewModel.Country}_{byCountryStatusViewModel.StatusType}";
                if (!_cache.Get(byCountryStatusCacheKey, out LiveByCountryAndStatusViewModel byCountryStatusVM))
                {
                    byCountryStatusVM = await GetCountriesViewModel <LiveByCountryAndStatusViewModel>();

                    string byCountryStatusUrl     = ExtractPlaceholderUrlApi(byCountryStatusVM);
                    var    byCountryStatusUrlList = await _apiService.GetAsync <IEnumerable <LiveByCountryAndStatus> >(byCountryStatusUrl);

                    byCountryStatusVM.LiveByCountryAndStatus = ApplySearchFilter(byCountryStatusUrlList, byCountryStatusVM);

                    _cache.Set(byCountryStatusCacheKey, byCountryStatusVM);
                }

                byCountryStatusViewModel = byCountryStatusVM;
            }

            return(View("Index", byCountryStatusViewModel));
        }