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 List<ICommand> GetCommandsForDevice(int deviceSensorid, int action) { var result = new List<ICommand>(); try { using (var db = new DbContext()) { var r = db.command_group .Where(n => n.devsensor_id == deviceSensorid) .Where(n => n.action == action) .ToList(); foreach (var cg in r) { ICommand c = new Command(-1, cg.pin, cg.value, cg.host, cg.type, cg.delay); result.Add(c); } } } catch (Exception e) { Logger.Error(e.Message); } return result; }
public List<ICommand> GetUnsentCommands() { var result = new List<ICommand>(); try { using (var db = new DbContext()) { // var r = db.command // .SqlQuery("select * from command where command_status = 0 and created_at < now()") // .ToList(); var r = db.command .Where(c => c.command_status == 0) .Where(c => c.created_at < DateTime.Now) .ToList(); foreach (var c in r) { ICommand command = new Command(c.commandid, (int) c.command_pin, c.command_value, c.command_host, c.command_type, 0); result.Add(command); } } } catch (Exception e) { Logger.Error(e.Message); } return result; }