Exemple #1
0
        public async Task <IEnumerable <CountryDto> > Handle(GetCountriesQuery request, CancellationToken cancellationToken)
        {
            var countryDtos = new List <CountryDto>();

            countryDtos = await _redisCacheManager.GetAsync <List <CountryDto> >(nameof(GetCountriesQuery));

            if (countryDtos != null)
            {
                return(countryDtos);
            }

            var countries = await _unitOfWork.Countries.GetAllAsync();

            countryDtos = countries.Select(c => new CountryDto
            {
                Id       = c.Id,
                SortName = c.SortName,
                Name     = c.Name
            }).ToList();

            await _redisCacheManager.SetAsync <List <CountryDto> >(nameof(GetCountriesQuery), countryDtos);

            return(countryDtos);
        }