public List <CCurrencyPair> GetAll() { String sqlExpression = "sp_GetAllCurrencyPairs"; List <CCurrencyPair> pairs = new List <CCurrencyPair>(); CCurrencyGateway curInfoGateway = new CCurrencyGateway(); using (SqlConnection conn = CDbConnection.GetConnection()) { SqlCommand command = new SqlCommand(sqlExpression, conn); command.CommandType = CommandType.StoredProcedure; var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { CCurrencyPair pair = new CCurrencyPair(); pair.BaseCurrency = curInfoGateway.Get((Int32)reader["BaseCurrencyID"]); pair.QuotedCurrency = curInfoGateway.Get((Int32)reader["QuotedCurrencyID"]); pair.ID = (Int32)reader["ID"]; pairs.Add(pair); } } reader.Close(); } return(pairs); }
public CCurrencyPair Get(Int32 id) { String sqlExpression = "sp_GetCurrencyPairById"; CCurrencyPair pair = new CCurrencyPair(); CCurrencyGateway curInfoGateway = new CCurrencyGateway(); using (SqlConnection conn = CDbConnection.GetConnection()) { SqlCommand command = new SqlCommand(sqlExpression, conn) { CommandType = CommandType.StoredProcedure }; SqlParameter idParam = new SqlParameter { ParameterName = "@id", Value = id }; command.Parameters.Add(idParam); try { var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { pair.BaseCurrency = curInfoGateway.Get((Int32)reader["BaseCurrencyID"]); pair.QuotedCurrency = curInfoGateway.Get((Int32)reader["QuotedCurrencyID"]); pair.ID = (Int32)reader["ID"]; } } else { pair = null; } reader.Close(); } catch (Exception e) { throw new Exception(e.Message + e.StackTrace); } } return(pair); }