public async Task AddForecastAsync(Context.Models.Forecast forecast)
 {
     using (var context = new ForecastContext(_connectionString))
     {
         context.Forecasts.Add(forecast);
         await context.SaveChangesAsync();
     }
 }
示例#2
0
        public async Task <WeatherForecast> Post()
        {
            var rng    = new Random();
            var entity = new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(rng.Next(0, 30)),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            };

            _ctx.Forecasts.Add(entity);
            await _ctx.SaveChangesAsync(HttpContext.RequestAborted);

            return(entity);
        }