Ejemplo n.º 1
0
        /// <summary>
        ///     Aplica el filtro de búsqueda para los casos de un país
        /// </summary>
        /// <param name="byCountryTotalList">La lista de países</param>
        /// <param name="byCountryTotalViewModel">La vista-modelo que contienen las opciones seleccionadas en el formulario de búsqueda</param>
        /// <returns>Lista con el país y el rango de fechas seleccionadas en la búsqueda, ordenadas de fechas más recientes a más antiguas</returns>
        private IEnumerable <ByCountryTotal> ApplySearchFilter(IEnumerable <ByCountryTotal> byCountryTotalList,
                                                               ByCountryTotalViewModel byCountryTotalViewModel)
        {
            if (byCountryTotalViewModel.Country == null)
            {
                return(byCountryTotalList.OrderByDescending(bc => bc.Date.Date));
            }

            return(byCountryTotalList
                   .Where(bc => bc.Country.Equals(byCountryTotalViewModel.Country) && bc.Status.Equals(byCountryTotalViewModel.StatusType))
                   .Where(bc => bc.Date >= byCountryTotalViewModel.DateFrom && bc.Date <= byCountryTotalViewModel.DateTo)
                   .OrderByDescending(bc => bc.Date.Date));
        }
Ejemplo n.º 2
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="byCountryTotalViewModel">La vista-modelo que contienen las opciones seleccionadas en el
        /// formulario de búsqueda</param>
        /// <returns>La URL de la API "total/country/status" con los parámetros de búsqueda sustituídos</returns>
        public string ExtractPlaceholderUrlApi(ByCountryTotalViewModel byCountryTotalViewModel)
        {
            string byCountryTotalApiUrl = GetAppSettingsUrlApiByKey(AppSettingsConfig.BY_COUNTRY_TOTAL_KEY);

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

            return(new StringBuilder(byCountryTotalApiUrl)
                   .Replace(AppSettingsConfig.COUNTRYNAME_PLACEHOLDER, byCountryTotalViewModel.Country)
                   .Replace(AppSettingsConfig.STATUS_PLACEHOLDER, byCountryTotalViewModel.StatusType)
                   .Replace(AppSettingsConfig.DATEFROM_PLACEHOLDER, byCountryTotalViewModel.DateFrom.ToString("dd/MM/yyyy"))
                   .Replace(AppSettingsConfig.DATETO_PLACEHOLDER, byCountryTotalViewModel.DateTo.ToString("dd/MM/yyyy"))
                   .ToString());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <ByCountryTotal> > > GetByCountryTotal(ByCountryTotalViewModel byCountryTotalViewModel)
        {
            if (ModelState.IsValid)
            {
                byCountryTotalCacheKey = $"{byCountryTotalCacheKey}_{byCountryTotalViewModel.Country}_{byCountryTotalViewModel.StatusType}_{byCountryTotalViewModel.DateFrom.ToShortDateString()}_{byCountryTotalViewModel.DateTo.ToShortDateString()}";
                if (!_cache.Get(byCountryTotalCacheKey, out ByCountryTotalViewModel byCountryTotalVM))
                {
                    byCountryTotalVM = await GetCountriesViewModel <ByCountryTotalViewModel>();

                    string byCountryTotalUrl  = ExtractPlaceholderUrlApi(byCountryTotalVM);
                    var    byCountryTotalList = await _apiService.GetAsync <IEnumerable <ByCountryTotal> >(byCountryTotalUrl);

                    byCountryTotalVM.ByCountryTotal = ApplySearchFilter(byCountryTotalList, byCountryTotalVM);

                    _cache.Set(byCountryTotalCacheKey, byCountryTotalVM);
                }

                byCountryTotalViewModel = byCountryTotalVM;
            }

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