public List <ScoreDAL> GetScoresRelatedToUserID(int UserID, int skip, int take) { List <ScoreDAL> ProposedReturnValue = new List <ScoreDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetScoresRelatedToUserID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@UserID", UserID); command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { ScoreMapper mapper = new ScoreMapper(reader); while (reader.Read()) { ScoreDAL score = mapper.ScoreFromReader(reader); ProposedReturnValue.Add(score); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public ScoreDAL FindScoreByScoreID(int ScoreID) { ScoreDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindScoreByScoreID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ScoreID", ScoreID); using (SqlDataReader reader = command.ExecuteReader()) { ScoreMapper mapper = new ScoreMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = mapper.ScoreFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Score with key {ScoreID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }