public ActionResult Weather() { //if (DateTime.Now.Subtract(weather._lastUpdate).TotalMinutes > 30) WeatherDate weather = GetWeather(); weather.Main.Temp = weather.Main.Temp.Split('.')[0]; weather._lastUpdate = DateTime.Now.ToString("D", new CultureInfo("ru-Ru")); weather.Weather[0].Icon = "https://openweathermap.org/img/w/" + weather.Weather[0].Icon + ".png"; return(View(weather)); }
public WeatherDate GetWeather() { string weather_date = "http://api.openweathermap.org/data/2.5/weather?lat=46.716178&lon=38.26780&id=524901&APPID=e49d9ff0bd027efc333242d89221f582&mode=json&lang=ru&units=metric"; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(weather_date); string str = req.RequestUri.ToString(); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); var jsonSource = new StreamReader(resp.GetResponseStream(), Encoding.UTF8).ReadToEnd(); string strin = jsonSource.ToString(); WeatherDate weather = JsonConvert.DeserializeObject <WeatherDate>(jsonSource); return(weather); }
public HomePageViewModel(IWeatherApiManager weatherApiManager, INavigationService navigationService, IUserDialogs userDialogs) : base(userDialogs) { _weatherApiManager = weatherApiManager; _navigationService = navigationService; GetCurrentWeatherCommand = new DelegateCommand(async() => await FetchCurrentWeather()); GetForecastCommand = new DelegateCommand(async() => await FetchForecast()); SelectedDateChangedCommand = new DelegateCommand(async() => await SelectedDateChanged()); Dates = new ObservableCollection <WeatherDate>(); var initialDate = DateTime.Now; SelectedDate = new WeatherDate { Date = initialDate }; Dates.Add(SelectedDate); for (int i = 1; i < 6; i++) { Dates.Add(new WeatherDate { Date = initialDate.AddDays(i), }); } Chart = new LineChart { BackgroundColor = SKColors.Transparent, PointMode = PointMode.Circle, LineMode = LineMode.Spline, PointSize = 50, AnimationDuration = TimeSpan.FromSeconds(2.3), LabelOrientation = Orientation.Horizontal, ValueLabelOrientation = Orientation.Horizontal, LabelColor = SKColors.White, LabelTextSize = 40, }; }