コード例 #1
0
ファイル: WeatherRepo.cs プロジェクト: AlexZayash/one
        public async Task <string> IsId(decimal lat, decimal lon)
        {
            var context = new DbContextOptions <OneContext>();

            using var db = new OneContext(_connectionString);
            var res = (await db.Coords.FirstOrDefaultAsync(elem => elem.Lat == lat && elem.Lon == lon))?.Id;

            if (res == null)
            {
                _logger.LogInformation("index not exist");
            }
            _logger.LogInformation($"index:{res}");
            return(res);
        }
コード例 #2
0
ファイル: WeatherRepo.cs プロジェクト: AlexZayash/one
        public async Task <string> InsertCoord(decimal lat, decimal lon)
        {
            using (var db = new OneContext(_connectionString))
            {
                await db.AddAsync(new Coord
                {
                    Id  = Guid.NewGuid().ToString(),
                    Lat = lat,
                    Lon = lon
                });

                await db.SaveChangesAsync();

                var res = (await db.Coords.FirstOrDefaultAsync(elem => elem.Lat == lat && elem.Lon == lon))?.Id;
                _logger.LogInformation($"coordinations is added :{lat} and {lon}");
                return(res);
            }
        }
コード例 #3
0
ファイル: WeatherRepo.cs プロジェクト: AlexZayash/one
        public async Task <List <CoordDto> > GetAllCoord()
        {
            using var db = new OneContext(_connectionString);
            var list = await db.Coords.ToListAsync();

            List <CoordDto> res = new List <CoordDto>();

            foreach (var l in list)
            {
                res.Add(
                    new CoordDto
                {
                    Id  = l.Id,
                    Lat = l.Lat,
                    Lon = l.Lon
                });
            }
            return(res);
        }
コード例 #4
0
ファイル: WeatherRepo.cs プロジェクト: AlexZayash/one
        public async Task InsertWeather(string id, WeatherDto currentWeather)
        {
            using (var db = new OneContext(_connectionString))
            {
                await db.AddAsync(new Weather
                {
                    Key      = Guid.NewGuid().ToString(),
                    Date     = currentWeather.Date,
                    FeelLike = currentWeather.FeelLike,
                    Id       = id,
                    Humidity = currentWeather.Humidity,
                    Pressure = currentWeather.Pressure,
                    Temp     = currentWeather.Temp
                });

                await db.SaveChangesAsync();

                _logger.LogInformation($"parameters of weather is added");
            }
        }
コード例 #5
0
ファイル: WeatherRepo.cs プロジェクト: AlexZayash/one
        public async Task <WeatherDto> GetWeatherFromDB(string id)
        {
            using var db = new OneContext(_connectionString);
            DateTime lastDate = db.Weathers.Where(elem => elem.Id == id).Max(elem => elem.Date);
            var      key      = await db.Weathers.FirstOrDefaultAsync(elem => elem.Date == lastDate && elem.Id == id);

            if (key == null)
            {
                return(null);
            }
            var res = await db.Weathers.FindAsync(key.Key);

            return(new WeatherDto
            {
                Date = res.Date,
                FeelLike = res.FeelLike,
                Humidity = res.Humidity,
                Pressure = res.Pressure,
                Temp = res.Temp
            });
        }