Ejemplo n.º 1
0
 public IEnumerable <TempData> GettempDatas()
 {
     if (_context.tempDatas.Count() == 0)
     {
         _context.tempDatas.Add(new TempData {
             Temperature = "24", Humidity = "55%"
         });
         _context.SaveChanges();
     }
     return(_context.tempDatas);
 }
Ejemplo n.º 2
0
        public IActionResult Create([FromBody] Device device)
        {
            if (device == null)
            {
                return(BadRequest());
            }

            _context.Devices.Add(device);
            _context.SaveChanges();

            return(CreatedAtRoute("GetDevice", new { id = device.Id }, device));
        }
        public IActionResult Create([FromBody] TemperatureItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _context.TemperatureItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetTemperature", new { id = item.Id }, item));
        }
Ejemplo n.º 4
0
        public TemperatureController(TemperatureContext context)
        {
            _context = context;

            if (_context.TemperatureItems.Count() == 0)
            {
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "London", Date = new DateTime(2018, 1, 1), Temperature = 6
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "London", Date = new DateTime(2018, 1, 2), Temperature = 8
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "London", Date = new DateTime(2018, 1, 3), Temperature = 4
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "New York", Date = new DateTime(2018, 1, 2), Temperature = 1
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "New York", Date = new DateTime(2018, 1, 3), Temperature = 3
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "Johannesburg", Date = new DateTime(2018, 1, 4), Temperature = 20
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "Johannesburg", Date = new DateTime(2018, 1, 3), Temperature = 20
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "Johannesburg", Date = new DateTime(2018, 1, 6), Temperature = 23
                });
                _context.TemperatureItems.Add(new TemperatureItem {
                    Location = "Johannesburg", Date = new DateTime(2018, 1, 5), Temperature = 22
                });


                _context.SaveChanges();
            }
        }
 private bool SaveData(TemperatureRestData value)
 {
     try
     {
         using (var db = new TemperatureContext())
         {
             var data = new TemperatureData()
             {
                 Date        = value.Date,
                 Humidity    = value.Humidity,
                 Location    = value.Location,
                 Temperature = value.Temperature
             };
             db.TemperatureData.Add(data);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        public static void SeedTestData(TemperatureContext context)
        {
            if (context.Devices.Any())
            {
                return;
            }

            var devices = new Device[]
            {
                new Device {
                    Location = "Garage", Name = "bt1234"
                },
                new Device {
                    Location = "Living Room", Name = "burglgrub"
                },
                new Device {
                    Location = "Stairs", Name = "BOULder4"
                },
            };

            foreach (var d in devices)
            {
                context.Devices.Add(d);
            }
            context.SaveChanges();

            var temperatureItems = new TemperatureItem[]
            {
                new TemperatureItem {
                    Temperature = 12.34, Device = devices[0], Timestamp = DateTime.Parse("2017-12-01 12:34:56")
                },
                new TemperatureItem {
                    Temperature = 13.34, Device = devices[1], Timestamp = DateTime.Parse("2017-12-01 12:35:56")
                },
                new TemperatureItem {
                    Temperature = 14.34, Device = devices[2], Timestamp = DateTime.Parse("2017-12-01 12:36:56")
                },
                new TemperatureItem {
                    Temperature = 15.34, Device = devices[0], Timestamp = DateTime.Parse("2017-12-01 12:37:56")
                },
                new TemperatureItem {
                    Temperature = 16.34, Device = devices[1], Timestamp = DateTime.Parse("2017-12-01 12:38:56")
                },
                new TemperatureItem {
                    Temperature = 17.34, Device = devices[2], Timestamp = DateTime.Parse("2017-12-01 12:39:56")
                },
                new TemperatureItem {
                    Temperature = 18.34, Device = devices[0], Timestamp = DateTime.Parse("2017-12-01 12:40:56")
                },
                new TemperatureItem {
                    Temperature = 19.34, Device = devices[1], Timestamp = DateTime.Parse("2017-12-01 12:41:56")
                },
                new TemperatureItem {
                    Temperature = 20.34, Device = devices[2], Timestamp = DateTime.Parse("2017-12-01 12:42:56")
                },
            };

            foreach (var t in temperatureItems)
            {
                context.TemperatureItems.Add(t);
            }
            context.SaveChanges();
        }