Esempio n. 1
0
        public List <OwnedItemDAL> GetOwnedItemsRelatedToUser(int UserID, int skip, int take)
        {
            List <OwnedItemDAL> proposedReturnValue = new List <OwnedItemDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetOwnedItemsRelatedToUser", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Skip", skip);
                    command.Parameters.AddWithValue("@Take", take);
                    command.Parameters.AddWithValue("@userID", UserID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        OwnedItemMapper m = new OwnedItemMapper(reader);
                        while (reader.Read())
                        {
                            OwnedItemDAL r = m.OwnedItemFromReader(reader);
                            proposedReturnValue.Add(r);
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(proposedReturnValue);
        }
Esempio n. 2
0
        public OwnedItemDAL FindOwnedItemByID(int ItemID)
        {
            OwnedItemDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command
                           = new SqlCommand("FindOwnedItemByID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ItemID", ItemID);
                    // need to configure the Text, Type and Parameters
                    // text was configured in the ctor (Line 58)
                    // type in line 60
                    // parameters in line 61

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