Exemplo n.º 1
0
        public async Task <ActionResult <PWSDetail> > GetPws(string id, string pwd)
        {
            Cache.CacheWeather cachePwsWeather = await new CacheWeatherLogic(_memoryCache, _context, _serviceFactory).GetPWSAsync(id, pwd);
            if (cachePwsWeather == null)
            {
                return(NotFound(Constants.NoPWS));
            }
            PWSDetail pws = await(from p in _context.Pws where p.IdPws == cachePwsWeather.IdPws select new PWSDetail {
                Alt = p.Alt, Desc = p.Desc, Id = p.Id, Lat = p.Lat, Lon = p.Lon, Name = p.Name, Pwd = p.Pwd
            }).FirstOrDefaultAsync();

            if (pws == null)
            {
                return(NotFound(Constants.NoPWS));
            }
            pws.WeatherRecordsCount = await _context.Weather.LongCountAsync(p => p.IdPws == cachePwsWeather.IdPws);

            pws.LastUpdateDateTime = await(from w in _context.Weather where w.IdPws == cachePwsWeather.IdPws orderby w.Id descending select w.Dateutc).FirstOrDefaultAsync();  // _context.Weather.Where(p => p.IdPws == cachePwsWeather.IdPws).OrderByDescending(p => p.Id).FirstOrDefaultAsync<Weather>();
            return(pws);
        }
Exemplo n.º 2
0
        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));
        }