Exemplo n.º 1
0
        public async Task <OperationResult <Weather> > GetWeatherAsync(int cityId)
        {
            OperationResult <Weather> result;
            var getCityOperationResult = await _cityRepository.GetCity(cityId);

            if (!getCityOperationResult.Succeed)
            {
                result = new OperationResult <Weather>(getCityOperationResult.ErrorCode);
                return(result);
            }

            var city = getCityOperationResult.Result;
            var getWeatherOperationResult = await _weatherApi.GetWeatherAsync(city.Name);

            if (!getWeatherOperationResult.Succeed)
            {
                result = new OperationResult <Weather>(getWeatherOperationResult.ErrorCode);
                return(result);
            }

            int celsius = getWeatherOperationResult.Result;

            var weather = new Weather(city, celsius);

            result = new OperationResult <Weather>(weather);

            return(result);
        }
        public async Task <Weather> GetWeatherAsync(int cityId)
        {
            var city = await _cityRepository.GetCity(cityId);

            int celsius = await _weatherApi.GetWeatherAsync(city.Name);

            var weather = new Weather(city, celsius);

            return(weather);
        }
Exemplo n.º 3
0
        public async Task <Weather> GetAsync(string country, string city)
        {
            try
            {
                var weather = await WeatherAPI.GetWeatherAsync(country, city);

                return(Weather.Get(weather));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(null);
            }
        }