示例#1
0
        public async Task UpdateAsync(WeatherMeasures weatherMeasure)
        {
            WeatherMeasures weatheremeasureRecord = await GetAsync(weatherMeasure.CityId, weatherMeasure.MeasureDate);

            weatheremeasureRecord.CopyValues(weatherMeasure);
            await _dbContext.SaveChangesAsync();
        }
示例#2
0
        public async Task DeleteAsync(int id)
        {
            WeatherMeasures weatheremeasureRecord = await GetAsync(id);

            _dbContext.WeatherMeasures.Remove(weatheremeasureRecord);
            await _dbContext.SaveChangesAsync();
        }
示例#3
0
        private async Task CreareOrUpdateRecordAsync(WeatherMeasures record)
        {
            bool isExists = await ChechIfExistsWeatherMeasureServiceRecordInDateBase(record.CityId, record.MeasureDate);

            if (isExists == true)
            {
                await _WeatherMeasureRepository.UpdateAsync(record);
            }
            else
            {
                await _WeatherMeasureRepository.CreateAsync(record);
            }
        }
示例#4
0
        public async Task CreateAsync(WeatherMeasures weatherMeasure)
        {
            var city = _dbContext.Cities.FirstOrDefault(i => i.CityId == weatherMeasure.CityId);

            if (city == null)
            {
                throw new Exception("City doesn't exist.");
            }

            //  _dbContext.Attach(weatherMeasure);
            //   city.WeatherMeasures.Add(weatherMeasure);

            await _dbContext.WeatherMeasures.AddAsync(weatherMeasure);

            await _dbContext.SaveChangesAsync();
        }
示例#5
0
        public async Task <List <WeatherMeasures> > ConvertDataFromExternalApiToWeatherMeasureRecord(JObject jObject, string cityName)
        {
            try
            {
                var WeatherDataFromExtnernalServiceList    = jObject["list"].ToList();
                List <WeatherMeasures> weatherMeasuresList = new List <WeatherMeasures>();
                var city = await _cityService.GetAsync(cityName);

                var cityId = city.CityId;
                int i      = 0;
                foreach (var item in WeatherDataFromExtnernalServiceList)
                {
                    i++;
                    var temperature = item["main"] != null && item["main"]["temp"] != null ? item["main"]["temp"].Value <decimal?>() : 0;
                    var humidity    = item["main"] != null && item["main"]["humidity"] != null ? item["main"]["humidity"].Value <int?>() : 0;
                    var rain        = item["rain"] != null && item["rain"]["3h"] != null ? item["rain"]["3h"].Value <decimal?>() : 0;
                    var snow        = item["snow"] != null && item["snow"]["3h"] != null ? item["snow"]["3h"].Value <decimal?>() : 0;
                    var wind        = item["wind"] != null && item["wind"]["speed"] != null ? item["wind"]["speed"].Value <decimal?>() : 0;

                    WeatherMeasures record = new WeatherMeasures();
                    record.SetTemperature(temperature);
                    record.SetHumidity(humidity);
                    record.SetRain(rain);
                    record.SetSnow(snow);
                    record.SetWind(wind);
                    record.SetMeasureDate(item["dt_txt"].Value <DateTime>());
                    record.CityId = cityId.Value;

                    weatherMeasuresList.Add(record);
                }
                return(weatherMeasuresList);
            }
            catch (Exception)
            {
                throw new Exception("Error in 'ConvertDataFromExternalApiToWeatherMeasureRecord' function.");
            }
        }
示例#6
0
 public async Task UpdateAsync(WeatherMeasureDTO weatherMeasureDTO)
 {
     WeatherMeasures weatherMeasure = _mapper.Map <WeatherMeasures>(weatherMeasureDTO);
     await _WeatherMeasureRepository.UpdateAsync(weatherMeasure);
 }
示例#7
0
        public async Task <WeatherMeasureDTO> GetAsync(int city_id, DateTime measurementDate)
        {
            WeatherMeasures WeatherMeasureRecord = await _WeatherMeasureRepository.GetAsync(city_id, measurementDate);

            return(_mapper.Map <WeatherMeasureDTO>(WeatherMeasureRecord));
        }
示例#8
0
        public async Task <WeatherMeasureDTO> GetAsync(int id)
        {
            WeatherMeasures WeatherMeasureRecord = await _WeatherMeasureRepository.GetAsync(id);

            return(_mapper.Map <WeatherMeasureDTO>(WeatherMeasureRecord));
        }