private List<Dto.Action> GetAll(StatementValue where) { List<string> columnNames = new List<string> (); columnNames.Add ("id"); columnNames.Add ("gameId"); columnNames.Add ("playerId"); columnNames.Add ("time"); columnNames.Add ("description"); List<List<string>> result; if (where != null) { result = this.Select (columnNames, where); } else { result = this.Select (columnNames); } PlayersTable playersTable = new PlayersTable (entity); GamesTable gamesTable = new GamesTable (entity); List<Dto.Action> actions = new List<Dto.Action> (); for (int i = 0; i < result[0].Count; i++) { Game game = gamesTable.Get (result [1] [i]); Player player = null; if (!string.IsNullOrEmpty (result [2] [i])) player = playersTable.Get (int.Parse (result [2] [i])); actions.Add (new Dto.Action (int.Parse (result [0] [i]), result [4] [i], game, player, DateTime.Parse (result [3] [i]))); } return actions; }
public Answer Get(int id) { try { List<string> columnNames = new List<string> (); columnNames.Add ("id"); columnNames.Add ("gameId"); columnNames.Add ("playerId"); columnNames.Add ("questionId"); columnNames.Add ("answer"); StatementValue where = new StatementValue () { Item1 = "id = @StatementValue0", Item2 = new List<string>() }; where.Item2.Add (id.ToString ()); List<List<string>> result = this.Select (columnNames, where); GamesTable gamesTable = new GamesTable (entity); PlayersTable playersTable = new PlayersTable (entity); QuestionsTable questionsTable = new QuestionsTable (entity); List<Answer> answers = new List<Answer> (); for (int i = 0; i < result[0].Count; i++) { Game game = gamesTable.GetShallow (int.Parse (result [1] [i])); Player player = null; if (!string.IsNullOrEmpty (result [4] [i])) player = playersTable.Get (int.Parse (result [2] [i])); Question question = questionsTable.Get (int.Parse (result [3] [i])); answers.Add (new Answer (int.Parse (result [0] [i]), question, game, player, result [4] [i])); } return answers.FirstOrDefault (); } catch (MySqlException ex) { switch (ex.Number) { case 0: throw new DatabaseException ("Cannot connect to server. Contact administrator", ex); case 1045: throw new DatabaseException ("Invalid username/password, please try again", ex); default: throw new DatabaseException (ex.Message, ex); } } }