public List <GameDAL> GetGames(int skip, int take) { List <GameDAL> ProposedReturnValue = new List <GameDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetGames", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { GameMapper mapper = new GameMapper(reader); while (reader.Read()) { GameDAL game = mapper.GameFromReader(reader); ProposedReturnValue.Add(game); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public GameDAL FindGameByGameID(int GameID) { GameDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindGameByGameID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@GameID", GameID); using (SqlDataReader reader = command.ExecuteReader()) { GameMapper mapper = new GameMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = mapper.GameFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Game with key {GameID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }