protected async Task storeCachedWeatherData(int IdPws, IEnumerable <Weather> lstWeather) { var insWeather = lstWeather.GroupBy(w => w.Dateutc.DayOfYear).GetAverage(windgustMax: true); using (var scope = _serviceFactory.CreateScope()) { pwsstoreContext context = scope.ServiceProvider.GetRequiredService <pwsstoreContext>(); await context.Weather.AddRangeAsync(insWeather); await context.SaveChangesAsync(); } }
public async Task <ActionResult <PWSDetail> > PostPws(PWSDetail pws, string secret) { if (secret != _configuration.GetValue <string>("PSWAddSecret")) { return(Unauthorized()); } var exists = await _context.Pws.FirstOrDefaultAsync(p => p.Id == pws.Id); if (exists != null) { return(NotFound("can't add pws")); } _context.Pws.Add(new Pws() { Alt = pws.Alt, Desc = pws.Desc, Id = pws.Id, Lat = pws.Lat, Lon = pws.Lon, Name = pws.Name, Pwd = pws.Pwd }); await _context.SaveChangesAsync(); return(Created($"Pws/{pws.Id}/{pws.Pwd}", pws)); }