// Constructor chaining with parameters public UserSettings(string userName, string homeAddress, string homeCity, string workAddress, int precison, TemperatureUOM temperatureUOM, DistanceUOM distanceUOM) : this(userName, homeAddress, homeCity, workAddress) { Precision = precison; TemperatureUOM = temperatureUOM; DistanceUOM = distanceUOM; }
public async Task <WeatherModel> GetModelAsync(string homeCity, int precision, TemperatureUOM temperatureUOM) { try { _repo = new WeatherRepo(homeCity); // Get entity from Repository. WeatherEntity entity = await _repo.GetEntityAsync(); // Map entity to model. WeatherModel model = MapEntityToModel(entity); // Calculate non-mappable values model = CalculateUnMappableValues(model, precision, temperatureUOM); // Todo: Implement bool if user wants metro or openweather icons if (true) { model.Icon = ConvertWeatherIcon(model.Icon); } return(model); } catch (HttpRequestException ex) { throw ex; } catch (Exception ex) { throw new ArgumentException("Unable to retrieve Weather Model", ex); } }
protected WeatherModel CalculateUnMappableValues(WeatherModel model, int precision, TemperatureUOM temperatureUOM) { model.TemperatureCelsius = TemperatureHelper.KelvinToCelsius(model.TemperatureKelvin, precision); model.TemperatureFahrenheit = TemperatureHelper.KelvinToFahrenheit(model.TemperatureKelvin, precision); switch (temperatureUOM) { case TemperatureUOM.Celsius: model.Temperature = model.TemperatureCelsius; break; case TemperatureUOM.Fahrenheit: model.Temperature = model.TemperatureFahrenheit; break; case TemperatureUOM.Kelvin: model.Temperature = model.TemperatureKelvin; break; default: model.Temperature = model.TemperatureCelsius; break; } DateTime sunrise = model.SunRiseMilliseconds.ConvertFromUnixTimestamp(); DateTime sunset = model.SunSetMilliSeconds.ConvertFromUnixTimestamp(); model.SunRise = sunrise.ToString("HH:mm"); model.SunSet = sunset.ToString("HH:mm"); return(model); }