public Procedure GetProcedure(string id) { try { Connection.Open(); } catch (SqlException e) { throw new BusinessException("Connection to database failed!", e); } try { var readCommand = new MySqlCommand($"SELECT * FROM procedures WHERE ID='{id}'", Connection); var reader = readCommand.ExecuteReader(); if (reader.Read()) { return(Procedure.Build( reader["Name"].ToString(), reader["Duration"].ToString(), reader["ID"].ToString() )); } else { throw new BusinessException("Cannot get procedure!", new Exception()); } } catch (SqlException e) { throw new BusinessException("Cannot get procedure!", e); } finally { Connection.Close(); } }
public List <Procedure> GetAllProcedures() { try { Connection.Open(); } catch (SqlException e) { throw new BusinessException("Connection to database failed!", e); } try { var readCommand = new MySqlCommand("SELECT * FROM procedures", Connection); var reader = readCommand.ExecuteReader(); var procedures = new List <Procedure>(); while (reader.Read()) { procedures.Add(Procedure.Build( reader["Name"].ToString(), reader["Duration"].ToString(), reader["ID"].ToString() )); } return(procedures); } catch (SqlException e) { throw new BusinessException("Cannot get procedures!", e); } finally { Connection.Close(); } }