public async Task <Models.Forecast> GetTodaysWeather(SimplyWeatherLocation location) { WeatherForecast weatherForecast = await _weatherApi.GetForecast(location); if (weatherForecast != null) { List <HourlyConditions> hourlyConditionsForDay = GetHourlyConditionsForDay(weatherForecast.Hourly); Models.Forecast forecast = new Models.Forecast { CurrentTemperature = weatherForecast.Current?.Temp != null ? (int)weatherForecast.Current.Temp : 0, HighTemp = GetHighTempForDay(hourlyConditionsForDay), LowTemp = GetLowempForDay(hourlyConditionsForDay), CurrentWindSpeed = weatherForecast.Current?.WindSpeed != null ? (int)weatherForecast.Current.WindSpeed : 0, FeelsLikeTemp = weatherForecast.Current?.FeelsLikeTemp != null ? (int)weatherForecast.Current.FeelsLikeTemp : 0, }; if (weatherForecast.Current?.Conditions?.Count > 0) { forecast.CurrentConditionsImageUrl = GetUrlForImageIcon(weatherForecast.Current.Conditions[0].Icon); forecast.CurrentConditions = weatherForecast.Current.Conditions[0].Description; } forecast.HourlyConditionsForDay = GetHourlyConditions(hourlyConditionsForDay); return(forecast); } return(null); }
public async override Task <bool> deleteAsync(Models.Forecast entity) { var result = await collection.UpdateOneAsync(Builders <Models.Forecast> .Filter.Eq("_id", entity.id), Builders <Models.Forecast> .Update.Set("track.enable", false) .Set("track.updated", DateTime.Now)); return(result.ModifiedCount > 0); }
public async override Task <bool> updateAsync(Models.Forecast entity, Models.Forecast newEntity) { newEntity.track = entity.track; newEntity.track.updated = DateTime.Now; var result = await collection.ReplaceOneAsync(Builders <Models.Forecast> .Filter.Eq("_id", entity.id), newEntity); return(result.ModifiedCount > 0); }
public async override Task <Models.Forecast> insertAsync(Models.Forecast entity) { entity.track = new Track() { enable = true, register = DateTime.Now, updated = DateTime.Now }; await collection.InsertOneAsync(entity); return(entity); }
public ForecastViewModel(DependencyObject dependency, Models.Forecast forecast) : base(dependency) { _forecast = forecast; if (_forecast.Cnt > 0) { var now = DateTime.Now; Days = _forecast.List .Where(listing => listing.DateTime.Date > now.Date) .Select(listing => new ForecastDay(dependency, listing, listing.Weather[0])) .ToList(); } }
public override async Task <Forecast> GetForecastOnDay(Models.City city) { if (city == null) { throw new Exception("City is not be null"); } var forecast = new Models.Forecast(); using (HttpClient client = new HttpClient()) { try { using (HttpResponseMessage response = await client.GetAsync(GetForecastUri(city.Name))) { if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); //Преобразуем JSON из респонса в JObject, и обращаемся к его ключам как к полям класса, dynamic responseObj = Newtonsoft.Json.Linq.JObject.Parse(responseJson); forecast.Temp = (float)responseObj.main.temp; forecast.Humidity = (float)responseObj.main.humidity; forecast.Pressure = (float)responseObj.main.pressure; } else { Console.WriteLine(response.ReasonPhrase); this.ServiceAvailable = false; } } } catch (Exception e) { Console.WriteLine(e.Message); this.ServiceAvailable = false; } } forecast.city = city; forecast.WeatherApi = this; return(forecast); }