public void WriteNewSensorsData(SensorsTemp[] sensors) { // Delete all the records from the tables using (var context = new SensorsContext()) { foreach (var elem in context.Sensors) { context.Remove(elem); } context.SaveChangesAsync(); } using (var context = new SensorsContext()) { foreach (var e in sensors) { //var e2 = new SensorsTempData() //{ // Id = e.Id, // CRC = e.CRC, // LastGet = e.LastGet, // Mount = e.Mount, // Number = e.Number, // Tempreture = e.Tempreture //}; //context.SensorsData.Add(e2); context.Sensors.Add(e.CreateSensorTempForBD()); //context.Sensors.Add(e); } context.SaveChangesAsync(); } //new Logger().LogMessage("Write to SQL end"); //// Select a previously inserted city record, //// insert a new person record referencing it, //// update a previously inserted person (specify the surname) //using (var context = new Vs2015WinFormsEfcSqliteCodeFirst20170304ExampleContext()) //{ // // Pay attention to the Include(city => city.People) part // // simple context.Cities.Single(city => city.Name == "London"); used instead // // would return the city but its .People list would be null. // // Also make sure to handle cases when there are more or less than one records // // meeting to the request conditions in the production code // var london = context.Cities.Include(city => city.People).Single(city => city.Name == "London"); // var peter = new Person { Name = "Peter", City = london }; // var john = london.People.Single(person => person.Name == "John"); // john.Surname = "Smith"; // context.Add(peter); // context.Update(john); // context.SaveChanges(); //} }
public HomeController(SensorsContext context) { _context = context; dbw = new DBWorker(_context); dr = new DataReciever(_context); }
public bool UpdateData(int Id, double temperature, double humidity, double smoke, DateTime time, Status status, SensorsContext context) { //get current Sensor var toUpdate = context.Sensors.Find(Id); //copy data var updated = toUpdate; //Update what you need updated.Temperature = temperature; updated.Humidity = humidity; updated.Smoke = smoke; updated.Updated = time; updated.CurrentStatus = status; //rewrite description updated.setInfo(); //update record in DB context.Entry(toUpdate).CurrentValues.SetValues(updated); //save changes context.SaveChanges(); return(true); }
public DBWorker(SensorsContext context) { _context = context; Sensors = new List <Sensor>(); }
public DataReciever(SensorsContext context) { myDelegate = new GetDataDelegate(RecieveData); _context = context; _dbw = new DBWorker(_context); }