public CityForecast[] Get() { CityForecast namurForecast = new CityForecast("namur", 5); CityForecast monsForecast = new CityForecast("mons", 5); return(new CityForecast[] { new CityForecast("namur", 5), new CityForecast("mons", 5) }); //return (GetForecastFromDatabase()); }
private static CityForecast GetCityForecast(Dal.Context.Models.Forecast forecast, City city) { var cityForecast = new CityForecast { DayForecasts = new List <DayForecast>(), Forecast = forecast }; if (city.Id != 0) { cityForecast.CityId = city.Id; } else { cityForecast.City = city; } return(cityForecast); }
public async Task <CityForecast> CreateCityForecast(string cityName, DateTime date, double humidity, double temperature) { _logger.LogDebug($"Added a city={cityName} on date={date}, humidity={humidity}, temperature={temperature}"); var cityForecast = new CityForecast() { CityName = cityName, Date = date, Humidity = humidity, Temperature = temperature }; await _dbContext.CityForecasts.AddAsync(cityForecast); await _dbContext.SaveChangesAsync(); return(cityForecast); }
private CityForecast[] GetForecastFromDatabase() { SqlConnection connection = new SqlConnection(@"Data Source = (LocalDb)\MSSQLLocalDb; Initial Catalog = bobLeServeur; Integrated Security = True; Pooling = False"); SqlCommand cmd = new SqlCommand("SELECT * FROM[Table]", connection); connection.Open(); SqlDataReader reader; reader = cmd.ExecuteReader(); List <CityForecast> forecasts = new List <CityForecast>(); while (reader.Read()) { CityForecast forecast = new CityForecast(); forecast.City = (string)reader["City"]; forecast.Tempe = (decimal)reader["tempe"]; forecasts.Add(forecast); } reader.Close(); connection.Close(); return(forecasts.ToArray()); }
public void ForecastNotError() { CityForecast fs = new CityForecast(); Cities cities = fs.Cities("Pirapozinho"); Assert.AreEqual(1, cities.Count); }
public void ForecastError() { CityForecast fs = new CityForecast(); Cities cities = fs.Cities("Presidente"); Assert.AreNotEqual(1, cities.Count); }