public ICommand Create(int pin, int? value, string host, string type) { try { ICommand c = new Command(-1, pin, value, host, type, 0); if (value == null) return c; var cm = new command() { command_pin = pin, command_value = value, command_host = host, command_type = type }; DbContext db = new DbContext(); db.command.Add(cm); db.SaveChanges(); c.CommandId = cm.commandid; return c; } catch (Exception e) { Logger.Error(e.Message); } return null; }
public void SetComplete() { using (var db = new DbContext()) { var c = db.command.Find(CommandId); if (c == null) return; c.command_status = 1; db.SaveChanges(); } }
public ISensorValue Create(int pin, decimal value, string host, string type) { try { ISensorValue sv = new SensorValue() {sensorid = pin, sensor_value = value, host = host, tipe = type}; using (var db = new DbContext()) { var svm = new sensor_value() {sensorid = pin, sensor_value1 = value, host = host, tipe = type}; db.sensor_value.Add(svm); db.SaveChanges(); } return sv; } catch (Exception e) { Logger.Error(e.Message); } return null; }
public void MarkAllComplete() { try { using (var db = new DbContext()) { var r = db.command .Where(n => n.command_status == 0) .ToList(); foreach (var c in r) { c.command_status = 1; } db.SaveChanges(); } } catch (Exception e) { Logger.Error(e.Message); } }