public ServiceResult <WeatherDto> UpdateWeatherAndReturn(WeatherDto latestWeather) { var request = (HttpWebRequest)WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?id=3103402&appid=0db985dfe762e26f24741f0393273666"); try { var response = request.GetResponse(); using (var responseStream = response.GetResponseStream()) { if (responseStream != null) { var reader = new StreamReader(responseStream, Encoding.UTF8); var obj = JsonConvert.DeserializeObject <WeatherHelper>(reader.ReadToEnd()); var weatherDto = _mapper.Map <WeatherDto>(obj); var weather = _mapper.Map <Weather.Weather>(weatherDto); _repository.Add(weather); _unitOfWork.Commit(); return(ServiceResult <WeatherDto> .Success(weatherDto)); } return(ServiceResult <WeatherDto> .Success(new WeatherDto())); } } catch { return(ServiceResult <WeatherDto> .Success(latestWeather)); } }
public async Task <ActionResult> Post(WeatherObservationDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var weatherObservation = new WeatherObservation { Date = dto.Date, TemperatureC = dto.TemperatureC, Summary = dto.Summary }; await _weatherRepository.Add(weatherObservation); return(Ok()); }