public void Update(Computer computer) { var model = ComputerModel.FromRepositoryType(computer); var sql = @" UPDATE ComputerModels SET AccessKey = @AccessKey, Address = @Address, EncryptionKey = @EncryptionKey, LastPing = @LastPing, LastScript_Id = @LastScript_Id, Name = @Name, Owner_Id = @Owner_Id WHERE Id = @Id "; var parameters = new { AccessKey = model.AccessKey, Address = model.Address, EncryptionKey = model.EncryptionKey, Id = model.Id, LastPing = model.LastPing, LastScript_Id = model.LastScript_Id, Name = model.Name, Owner_Id = model.Owner_Id, }; _connection.Execute(sql, parameters); }
public void Add(Computer computer) { var model = ComputerModel.FromRepositoryType(computer); var sql = @" INSERT INTO ComputerModels ( AccessKey, Address, EncryptionKey, LastPing, LastScript_Id, Name, Owner_Id ) VALUES ( @AccessKey, @Address, @EncryptionKey, @LastPing, @LastScript_Id, @Name, @Owner_Id ) SELECT CAST(IDENT_CURRENT('ComputerModels') as int) "; var parameters = new { AccessKey = model.AccessKey, Address = model.Address, EncryptionKey = model.EncryptionKey, LastPing = model.LastPing, LastScript_Id = model.LastScript_Id, Name = model.Name, Owner_Id = model.Owner_Id, }; var id = _connection.QuerySingle <int>(sql, parameters); computer.SetId(id); }
public Task[] ForComputer(Computer computer, DateTime now, IRepositoryModelCache cache = null) { var computerModel = ComputerModel.FromRepositoryType(computer); var sql = @" SELECT * FROM TaskModels WHERE Target_Id = @Target_Id AND ReceivedTimestamp IS NULL AND Expiration > @Now "; var parameters = new { Now = now, Target_Id = computerModel.Id, }; var models = _connection.Query <TaskModel>(sql, parameters).ToArray(); var result = models .Select(x => x.ToRepositoryType(cache, _computerRepository, _scriptRepository, _userRepository)) .ToArray(); return(result); }