public bool Delete(Contractor contractor) { using (var command = new FbCommand()) { command.Connection = ConnectionHelper.Connection; if (command.Connection.State != System.Data.ConnectionState.Open) command.Connection.Open(); command.CommandText = @"DELETE FROM CONTRACTORS WHERE ID=@ID"; command.Parameters.AddWithValue("@ID", contractor.Id); try { command.ExecuteNonQuery(); return true; } catch { return false; } } }
public Contractor Save(Contractor contractor) { using (var command = new FbCommand()) { command.Connection = ConnectionHelper.Connection; if (command.Connection.State != System.Data.ConnectionState.Open) command.Connection.Open(); command.CommandText = @"UPDATE OR INSERT INTO CONTRACTORS(ID,NAME,ISNOTACTIVE) VALUES(@ID,@NAME,@ISNOTACTIVE) MATCHING(ID) RETURNING ID"; command.Parameters.AddWithValue("@ID", contractor.Id); command.Parameters.AddWithValue("@NAME", contractor.Name); command.Parameters.AddWithValue("@ISNOTACTIVE", contractor.IsNotActive); contractor.Id = (int)command.ExecuteScalar(); return contractor; } }