public void SetRecords(House house) { foreach (Room r in house.Rooms) { r.ChangeValues(); if (r.RoomHumidity > r.RoomHumidityHigh || r.RoomHumidityHigh == null) { r.RoomHumidityHigh = r.RoomHumidity; r.RHHTimestamp = DateTime.Now; } if (r.RoomHumidity < r.RoomHumidityLow || r.RoomHumidityLow == null) { r.RoomHumidityLow = r.RoomHumidity; r.RHLTimestamp = DateTime.Now; } if (r.RoomTemperature > r.RoomTemperatureHigh || r.RoomTemperatureHigh == null) { r.RoomTemperatureHigh = r.RoomTemperature; r.RTHTimestamp = DateTime.Now; } if (r.RoomTemperature < r.RoomTemperatureLow || r.RoomTemperatureLow == null) { r.RoomTemperatureLow = r.RoomTemperature; r.RTLTimestamp = DateTime.Now; } using (var db = new CenitoIoTContext()) { db.Entry(r).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public IHttpActionResult PutRoom(int id, Room room) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != room.RoomId) { return(BadRequest()); } db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }