Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public KnightDAL KnightFromReader(SqlDataReader reader)
        {
            KnightDAL ProposedReturnValue = new KnightDAL();

            ProposedReturnValue.KnightID     = reader.GetInt32(OffsetToKnightID);
            ProposedReturnValue.KnightName   = reader.GetString(OffsetToKnightName);
            ProposedReturnValue.Strength     = reader.GetInt32(OffsetToStrength);
            ProposedReturnValue.Dexterity    = reader.GetInt32(OffsetToDexterity);
            ProposedReturnValue.Constitution = reader.GetInt32(OffsetToConstitution);
            ProposedReturnValue.Precision    = reader.GetInt32(OffsetToPrecision);
            ProposedReturnValue.OrderID      = reader.GetInt32(OffsetToOrderID);
            //ProposedReturnValue.OrderName = reader.GetString(OffsetToOrderName);
            //ProposedReturnValue.OrderBonus = reader.GetString(OffsetToOrderBonus);
            ProposedReturnValue.UserID = reader.GetInt32(OffsetToUserID);
            //ProposedReturnValue.Username = reader.GetString(OffsetToUsername);
            //ProposedReturnValue.EmailAddress = reader.GetString(OffsetToEmailAddress);
            //ProposedReturnValue.Password = reader.GetString(OffsetToPassword);
            //ProposedReturnValue.Hash = reader.GetString(OffsetToHash);
            //ProposedReturnValue.RoleID = reader.GetInt32(OffsetToRoleID);

            return(ProposedReturnValue);
        }
Exemplo n.º 3
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);
        }