示例#1
0
        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);
        }
示例#2
0
        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);
        }
        public ScoreDAL ScoreFromReader(System.Data.SqlClient.SqlDataReader reader)
        {
            ScoreDAL ProposedReturnValue = new ScoreDAL();

            ProposedReturnValue.ScoreID  = reader.GetInt32(OffsetToScoreID);
            ProposedReturnValue.Score    = reader.GetInt32(OffsetToScore);
            ProposedReturnValue.UserID   = reader.GetInt32(OffsetToUserID);
            ProposedReturnValue.GameID   = reader.GetInt32(OffsetToGameID);
            ProposedReturnValue.UserName = reader.GetString(OffsetToUserName);
            ProposedReturnValue.GameName = reader.GetString(OffsetToGameName);
            return(ProposedReturnValue);
        }