Exemplo n.º 1
0
        /// <summary>
        ///     Aplica el filtro de búsqueda para los casos de un país
        /// </summary>
        /// <param name="byCountryList">La lista de países</param>
        /// <param name="byCountryViewModel">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>
        public IEnumerable <ByCountry> ApplySearchFilter(IEnumerable <ByCountry> byCountryList,
                                                         ByCountryViewModel byCountryViewModel)
        {
            if (byCountryViewModel.Country == null)
            {
                return(byCountryList.OrderByDescending(bc => bc.Date.Date));
            }

            return(byCountryList
                   .Where(bc => bc.Country.Equals(byCountryViewModel.Country) && bc.Status.Equals(byCountryViewModel.StatusType))
                   .Where(bc => bc.Date >= byCountryViewModel.DateFrom && bc.Date <= byCountryViewModel.DateTo)
                   .OrderByDescending(bc => bc.Date.Date));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Sustituye los placeholders marcados entre llaves "{}" 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="byCountryViewModel">La vista-modelo que contienen las opciones seleccionadas en el
        /// formulario de búsqueda</param>
        /// <returns>URL de la API "country/status" con los parámetros de búsqueda sustituídos</returns>
        public string ExtractPlaceholderUrlApi(ByCountryViewModel byCountryViewModel)
        {
            string byCountryApiUrl = GetAppSettingsUrlApiByKey(AppSettingsConfig.BY_COUNTRY_KEY);

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

            return(new StringBuilder(byCountryApiUrl)
                   .Replace(AppSettingsConfig.COUNTRYNAME_PLACEHOLDER, byCountryViewModel.Country)
                   .Replace(AppSettingsConfig.STATUS_PLACEHOLDER, byCountryViewModel.StatusType)
                   .Replace(AppSettingsConfig.DATEFROM_PLACEHOLDER, byCountryViewModel.DateFrom.ToString("yyyy-MM-dd"))
                   .Replace(AppSettingsConfig.DATETO_PLACEHOLDER, byCountryViewModel.DateTo.ToString("yyyy-MM-dd"))
                   .ToString());
        }
Exemplo n.º 3
0
        public async Task <ActionResult> GetByCountry(ByCountryViewModel byCountryViewModel)
        {
            if (ModelState.IsValid)
            {
                byCountryCacheKey = $"{byCountryCacheKey}_{byCountryViewModel.Country}_{byCountryViewModel.StatusType}_{byCountryViewModel.DateFrom.ToShortDateString()}_{byCountryViewModel.DateTo.ToShortDateString()}";
                if (!_cache.Get(byCountryCacheKey, out ByCountryViewModel byCountryVM))
                {
                    byCountryVM = await GetCountriesViewModel <ByCountryViewModel>();

                    string byCountryUrl  = ExtractPlaceholderUrlApi(byCountryVM);
                    var    byCountryList = await _apiService.GetAsync <IEnumerable <ByCountry> >(byCountryUrl);

                    byCountryVM.ByCountry = ApplySearchFilter(byCountryList, byCountryVM);

                    _cache.Set(byCountryCacheKey, byCountryVM);
                }

                byCountryViewModel = byCountryVM;
            }

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