public IHttpActionResult PutWindow(int id, Window window) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != window.Id) { return(BadRequest()); } db.Entry(window).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WindowExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static void UpdateTemperatureToDb() { SerialPort arduinoPort = PortController.GetArduinoPort(); if (arduinoPort.IsOpen) { arduinoPort.Write("TEMPERATURE_INDOOR"); string temperatureString = arduinoPort.ReadLine(); Double temperature = Double.Parse(temperatureString); arduinoPort.Write("TEMPERATURE_OUTDOOR"); string outTemperatureString = arduinoPort.ReadLine(); Double outTemperature = Double.Parse(outTemperatureString); dbTemp.InOutTemperatures.Add(new InOutTemperature(temperature, outTemperature, DateTime.Now)); dbTemp.SaveChanges(); arduinoPort.Write("WINDOW_STATUS"); string windowStatusString = arduinoPort.ReadLine(); string cleanWindowStatus = windowStatusString.Trim(); bool windowOpen = (cleanWindowStatus == "WINDOW_OPEN"); dbWind.Windows.Add(new Window(windowOpen, DateTime.Now)); dbWind.SaveChanges(); arduinoPort.Write("HEATER_STATUS"); string heatStatusString = arduinoPort.ReadLine(); string eanHeaterStatus = heatStatusString.Trim(); bool heatOn = (eanHeaterStatus == "HEATER_ON"); dbHeat.Heats.Add(new Heat(heatOn, DateTime.Now)); dbHeat.SaveChanges(); } else { throw new InvalidOperationException("Arduino port not found"); } }