public IWeatherViewModel Create( WeatherContract weatherContract, TemperatureUnit temperatureUnit, WindSpeedUnit windSpeedUnit) { return(new WeatherViewModel(weatherContract, temperatureUnit, windSpeedUnit)); }
public WeatherViewModel( WeatherContract weatherContract, TemperatureUnit temperatureUnit, WindSpeedUnit windSpeedUnit) { Time = $"{weatherContract.DateTime:HH:mm}"; Description = weatherContract.Description; switch (temperatureUnit) { case TemperatureUnit.Celsius: Temperature = $"{weatherContract.Celsius} °C"; break; case TemperatureUnit.Fahrenheit: Temperature = $"{weatherContract.Fahrenheit} °F"; break; default: throw new ArgumentOutOfRangeException(nameof(temperatureUnit), temperatureUnit, null); } switch (windSpeedUnit) { case WindSpeedUnit.MetersPerSecond: WindSpeed = $"{weatherContract.MetersPerSecond} м/с"; break; case WindSpeedUnit.MilesPerHour: WindSpeed = $"{weatherContract.MilesPerHour} М/ч"; break; case WindSpeedUnit.KilometersPerHour: WindSpeed = $"{weatherContract.KilometersPerHour} Км/с"; break; default: throw new ArgumentOutOfRangeException(nameof(windSpeedUnit), windSpeedUnit, null); } Precipitation = weatherContract.Precipitation == null ? "Без осдаков" : $"{weatherContract.Precipitation.Value}"; }