public ActionResult CurrentWeather(string city) { if (string.IsNullOrWhiteSpace(city)) { return(View()); } CurrentWeather weather = _weatherService.GetCurrentWeather(city); CurrentWeatherDTO weatherDTO = new CurrentWeatherDTO { City = weather.City.Name, Country = weather.City.Country, WeatherIcon = weather.Weather.Icon, Temperature = $"{weather.Temperature.Value.Split('.')[0]} °C", Cloudiness = weather.Clouds.Name.ToUpper(), Wind = $"{weather.Wind.Speed.Name}, {weather.Wind.Speed.Value} m/s", WindDirection = $"{weather.Wind.Direction.Name} ( {weather.Wind.Direction.Value} )", Pressure = $"{weather.Pressure.Value} {weather.Pressure.Unit.ToLower()}", Humidity = $"{weather.Humidity.Value} {weather.Humidity.Unit}", Sunrise = weather.City.Sun.Rise.Split('T')[1], Sunset = weather.City.Sun.Set.Split('T')[1], CoordLat = weather.City.Coord.Lat, CoordLon = weather.City.Coord.Lon }; return(PartialView("_currentWeather", weatherDTO)); }
public CurrentWeatherViewModel(CurrentWeatherDTO currentWeather) { if (currentWeather != null) { this.CityName = currentWeather.City; this.Humidity = currentWeather.Humidity; this.Icon = currentWeather.Icon; this.Pressure = (int)currentWeather.Pressure; this.Temperature = currentWeather.Temperature; this.WindSpeed = currentWeather.WindSpeed; } }
public string GetReadableInfo(CurrentWeatherDTO weatherDto) { return($"📍 Location: {weatherDto.Name}\n" + "🌡️ Current temperature: \n" + $"{weatherDto.Main.Temperature}°C and it feels like {weatherDto.Main.FeelsLike}°C\n" + $"Humidity: {weatherDto.Main.Humidity}%\n" + "💨 Wind:\n" + $"Speed - {weatherDto.Wind.Speed}km/h\n" + $"Degree - {weatherDto.Wind.Degree}%\n" + $"Pressure - {weatherDto.Main.Pressure}hpa\n" + $"Primarily: {weatherDto.Weather.ElementAt(0).Main}\n"); }
async Task ExecuteLoadCommand() { if (IsBusy) { return; } IsBusy = true; try { // Get weather Xamarin.Essentials.Location location = await Geolocation.GetLastKnownLocationAsync(); if (location == null) { location = new Xamarin.Essentials.Location(50.0, 22.0); } Weather = await GetForecastWeather(location, Configuration.API_LANGAUGE); // Get weather descriptions to download images CurrentWeatherDTO descriptionWeather = await GetWeather(location, "en"); string condition = descriptionWeather.Current.Condition.Text; SetBackgroundImage(condition); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public string GetIconUrl(CurrentWeatherDTO weatherDto) { return($"https://openweathermap.org/img/w/{weatherDto.Weather.ElementAt(0).Icon}.png"); }