Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,AutumnStart,AutumnDateTime,WinterStart,WinterDateTime")] MeteorologicalSeason meteorologicalSeason)
        {
            if (ModelState.IsValid)
            {
                DateTime WinterCheck = new DateTime(2016, 10, 01);
                DateTime AutumnCheck = new DateTime(2016, 10, 01);
                var      Autumn      = MeteorologicalSeason.AutumnDate(_context, AutumnCheck);
                var      Winter      = MeteorologicalSeason.WinterDate(_context, WinterCheck);
                if (Autumn == null)
                {
                    meteorologicalSeason.AutumnStart = "Hösten kom aldrig 2016";
                }
                if (Winter == null)
                {
                    meteorologicalSeason.WinterStart = "Vintern kom aldrig 2016";
                }
                if (Winter != null)
                {
                    meteorologicalSeason.WinterStart = "Vintern faller på detta datum 2016";
                }
                if (Autumn != null)
                {
                    meteorologicalSeason.AutumnStart = "Hösten faller på detta datum 2016";
                }
                meteorologicalSeason.AutumnDateTime = Autumn;
                meteorologicalSeason.WinterDateTime = Winter;
                _context.Add(meteorologicalSeason);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(meteorologicalSeason));
        }
        private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            int interval = Convert.ToInt32(ConfigHelper.Get("Interval:Data"));

            if (DateTime.Now.Minute % interval != 0)
            {
                return;
            }

            try
            {
                Weather weather = await GetWeatherAsync();

                using WeatherContext context = new WeatherContext();
                context.Add(weather);
                context.SaveChanges();

                if (DateTime.Now.Minute == 0 || DateTime.Now.Minute == 30)
                {
                    await PostWeiboAsync(weather);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,SelectDate,AvgTemp,AvgHum,MouldRisk")] InformationTableIndoor informationTableIndoor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(informationTableIndoor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(informationTableIndoor));
        }
        public async Task <IActionResult> Create([Bind("date,clocktime,temperature,humidity,airpressure")] Weatherinfo weatherinfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(weatherinfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(weatherinfo));
        }
        public IEnumerable <WeatherForecast> Get()
        {
            var weather = new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(1),
                TemperatureC = 56,
                Summary      = Summaries[1]
            };

            _weatherContext.Add(weather);
            //_weatherContext.SaveChangesAsync();

            //var rng = new Random();
            return(Enumerable.Range(1, 5).Select(index => weather)
                   .ToArray());
        }
Esempio n. 6
0
        public void LoadWeatherData() //populate db
        {
            if (_context.WeatherSensors.Any())
            {
                return;
            }

            string file    = System.IO.File.ReadAllText(@"C:\IT-Högskolan\Databaser\Entity Framework\Inlämningsuppgift\WeatherDataConsole\EFDataAccessLibrary\Data\tempdata.csv");
            var    datas   = new List <WeatherData>();
            var    sensors = new List <WeatherSensor>();

            var records = file.Split('\n');

            foreach (var record in records)
            {
                var props = record.Split(',');
                if (!sensors.Any(s => s.Location == props[1]))
                {
                    //create sensor...
                    var sensor = new WeatherSensor {
                        Location = props[1]
                    };
                    _context.Add(sensor);
                    _context.SaveChanges();
                    sensors.Add(sensor);
                }

                var ws = sensors.Where(s => s.Location == props[1]).FirstOrDefault();

                var data = new WeatherData
                {
                    Collected_On    = DateTime.Parse(props[0]),
                    Temperature     = float.Parse(props[2], System.Globalization.CultureInfo.InvariantCulture),
                    Humidity        = byte.Parse(props[3]),
                    WeatherSensor   = ws,
                    WeatherSensorId = ws.Id
                };
                datas.Add(data);
            }
            _context.BulkInsert(datas);
        }
 public bool AddHistoricalWeather(HistoricalWeatherDto historicalWeatherDto)
 {
     try
     {
         //var historicalWeather = _mapper.Map<HistoricalWeather>(historicalWeatherDto);
         var historicalWeather = new HistoricalWeather
         {
             ThermalSensation = historicalWeatherDto.ThermalSensation,
             Temperature      = historicalWeatherDto.Temperature,
             City             = _context.City.FirstOrDefault(x => x.Id == historicalWeatherDto.City.Id),
             Country          = _context.Country.FirstOrDefault(x => x.Id == historicalWeatherDto.Country.Id),
         };
         _context.Add <HistoricalWeather>(historicalWeather);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Error al guardar el historico");
         return(false);
     }
     return(true);
 }