public HistoricoSensor Post(int id, [FromBody] AtualizaSensorViewModel model) { var sensor = this._db.sensores.Single(s => s.Id == id); sensor.valor = model.valor; sensor.latitude = model.latitude; sensor.longitude = model.longitude; this._db.sensores.Update(sensor); this._db.SaveChanges(); var historicoSensor = new HistoricoSensor(); historicoSensor.data = DateTime.Now; historicoSensor.latitude = model.latitude; historicoSensor.longitude = model.longitude; historicoSensor.sensor = sensor; historicoSensor.valor = model.valor; this._db.historicoSensores.Add(historicoSensor); this._db.SaveChanges(); return(historicoSensor); }
public Sensor Put(int id, [FromBody] AtualizaSensorViewModel model) { var sensor = this._db.sensores.SingleOrDefault(s => s.Id == id); sensor.valor = model.valor; sensor.lat = model.lat; sensor.lng = model.lng; var entradaHistorico = new HistoricoSensor( data: DateTime.Now, sensor: sensor, valor: model.valor, lat: model.lat, lng: model.lng ); this._db.sensores.Update(sensor); this._db.SaveChanges(); this._db.historicoSensores.Add(entradaHistorico); this._db.SaveChanges(); return(sensor); }