public IEnumerable <WeatherForecast> Post([FromBody] ForecastLocation body) { var rng = new Random(); return(Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray()); }
public UserWeatherForecast Get() { _logger.LogInformation("Getting Five Day Forecast"); _logger.LogDebug("Checking for user token"); int?userId = null; var uwf = new UserWeatherForecast() { UserId = userId }; if (userId.HasValue) { _logger.LogDebug("Token found: Reading database for user details"); } else { _logger.LogDebug("Anonymous access: Returning default weather"); uwf.UserLocationForecasts = new List <ForecastLocation>(); var defaultLocation = new ForecastLocation() { LocationCode = 0, LocationName = "Default Location", Forecast = new List <WeatherForecast>() }; uwf.UserLocationForecasts.Add(defaultLocation); } foreach (var loc in uwf.UserLocationForecasts) { loc.Forecast.AddRange(GetRandomFiveDays()); } return(uwf); }
/// <summary> /// ToString override /// </summary> /// <returns>string</returns> public override string ToString() { return(ForecastLastupdate.ToString() + "\n\n" + ForecastLocation.ToString() + "\n" + ForecastWeather.ToString() + "\n" + ForecastSunRise.ToString() + "\n" + ForecastTemperature.ToString() + "\n" + ForecastHumidity + "\n" + ForecastPressure.ToString() + "\n" + ForecastWindSpeed.ToString() + "\n" + ForecastWindDirection.ToString() + "\n" + ForecastClouds.ToString() + "\n" + ForecastPrecipitation.ToString()); }