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 void SetDataFromObject(Sensor newSensor) { _context.Sensors.Add(newSensor); _context.SaveChanges(); }