コード例 #1
0
        public List <KnightDAL> GetKnightsRelatedToUser(int skip, int take, int UserID)
        {
            List <KnightDAL> proposedReturnValue = new List <KnightDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetKnightsRelatedToUser", _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())
                    {
                        KnightMapper m = new KnightMapper(reader);
                        while (reader.Read())
                        {
                            KnightDAL r = m.KnightFromReader(reader);
                            proposedReturnValue.Add(r);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(proposedReturnValue);
        }
コード例 #2
0
        public KnightDAL FindKnightByID(int KnightID)
        {
            KnightDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command
                           = new SqlCommand("FindKnightByID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@KnightID", KnightID);


                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        KnightMapper m     = new KnightMapper(reader);
                        int          count = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = m.KnightFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new
                                  Exception($"Found more than 1 knight with key {KnightID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }