Пример #1
0
        public Task <WeatherForcastResponseDto> Get([FromQuery] WeatherForcastRequestDto requestDto)
        {
            requestDto.Validate();
            Func <Task <WeatherForcastResponseDto> > weatherForecastCache = () => _weatherForcastService.Get(requestDto);

            return(_cache.GetOrAddAsync <WeatherForcastResponseDto>(requestDto.GetRequestValue().value, weatherForecastCache, DateTimeOffset.Now.AddHours(1)));
        }
Пример #2
0
        public async Task <WeatherForcastResponseDto> Get(WeatherForcastRequestDto requestDto)
        {
            WeatherForecastResponse weatherForecastResponse = new WeatherForecastResponse();

            _ = (requestDto.GetRequestValue() switch
            {
                (nameof(requestDto.City), _) => weatherForecastResponse =
                    await _weatherForecast.GetWeatherForecastByCityNameAsync(requestDto.City, Countries.Germany),
                (nameof(requestDto.ZipCode), _) => weatherForecastResponse =
                    await _weatherForecast.GetWeatherForecastByZipCodeAsync(requestDto.ZipCode, Countries.Germany),
                (_, _) => throw new RequestInvalidException("Input must be identified!")
            });