public static List<SymbolModel> GetAllSymbols() { var symbolsList = new List<SymbolModel>(); const string sql = "COMMIT; SELECT * FROM " + TblSymbols; MySqlDataReader reader = GetReader(sql); if (reader != null) { try { while (reader.Read()) { var symbol = new SymbolModel {SymbolId = reader.GetInt32(0), SymbolName = reader.GetString(1)}; symbolsList.Add(symbol); } } finally { reader.Close(); } } return symbolsList; }
public static List<SymbolModel> GetSymbolsForUser(int userId) { var symbolsList = new List<SymbolModel>(); string sql = "SELECT * FROM " + TblSymbolsForUsers + " LEFT JOIN " + TblSymbols + " ON " + TblSymbolsForUsers + ".SymbolID = " + TblSymbols + ".ID" + " WHERE " + TblSymbolsForUsers + ".UserID = '" + userId + "' ; COMMIT;"; MySqlDataReader reader = GetReader(sql); if (reader != null) { try { while (reader.Read()) { var symbol = new SymbolModel {SymbolId = reader.GetInt32(4), SymbolName = reader.GetString(5)}; if(!symbolsList.Exists(a=>a.SymbolName==symbol.SymbolName)) symbolsList.Add(symbol); } } finally { reader.Close(); } } return symbolsList; }