Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to return UserInfo array?How to return UserInfo array?
Previous
 
Next
New Post
4/18/2012 8:58 PM
 

Hi guys,

I'm reading userid that match a certain conditions and trying to return the corresponding array of UserInfo.

So far, I'm not succeding. Here's what I'm doing:

public static string AdvancedSearchStatement = "SELECT up.userid " +
                                                        "FROM ProfilePropertyDefinition ppd " +
                                                        "JOIN UserProfile up ON ppd.PropertyDefinitionID = up.PropertyDefinitionID " +
                                                        "WHERE ppd.PropertyName = 'Country' AND up.PropertyValue = '{0}' " +
                                                        "AND EXISTS ( " +
                                                                      "SELECT 1 " +
                                                                      "FROM  ProfilePropertyDefinition ppd1 " +
                                                                      "JOIN UserProfile up1 ON ppd1.PropertyDefinitionID = up1.PropertyDefinitionID " +
                                                                      "WHERE ppd1.PropertyName = 'Region' AND up1.PropertyValue = '{1}' " +
                                                                      "AND up1.userid  = up.userid " +
                                                                    ") " +
                                                        "AND EXISTS ( " +
                                                                      "SELECT 1 " +
                                                                      "FROM  ProfilePropertyDefinition ppd2 " +
                                                                      "JOIN UserProfile up2 ON ppd2.PropertyDefinitionID = up2.PropertyDefinitionID " +
                                                                      "WHERE ppd2.PropertyName = 'City' AND up2.PropertyValue = '{2}' " +
                                                                      "AND up2.userid  = up.userid " +
                                                                    ") "; 

 

public IEnumerable<UserInfo> GetUserByAdvancedSearchCriteria(AdvancedSearchCriteria searchCriteria, int portalId)
        {
            IEnumerable<UserInfo> userCollection = null;
            string sqlStatement = String.Format(SqlCommands.AdvancedSearchStatement,             searchCriteria.Country, searchCriteria.State, searchCriteria.City);
            using (IDataReader reader = this._dataLayer.ExecuteSQL(sqlStatement))
            {               
               userCollection = UserController.FillUserCollection(portalId, reader);
            }

            return userCollection;
        }

Since I'm using dnn 6.1

the following instruction warns me that the method FillUserCollection is obsolete:

userCollection = UserController.FillUserCollection(portalId, reader);

The same line gives me a runtime error saying that it cannot convert its return value to IEnumerable<UserInfo>

Thanks for any help on this issue

 

 

 
New Post
4/19/2012 1:15 PM
 

     When you call UserController.FillUserCollection(portalId, reader) method , it will call public static UserInfo FillUserInfo(int portalId, IDataReader dr, bool closeDataReader) method to fill user info.

     As you will see this method in Library\Entities\Users\UserController.cs, this method require your provide specific data reader which contains [UserID],[IsSuperUser],[IsDeleted]...etc. Obviously, the data reader you provide doesn't meet it. (yours only contain up.userid field). So it will raise error.



Over 20 + professional dnn modules for News Article, Store, Video Gallery, Photo Gallery, Ultra Flash Player,YouTube Video, Image Slide show, Skin Chameleon and much more from DnnModule.com
 
New Post
4/20/2012 10:29 PM
 

Thanks for the reply DnnModule,

I finally did it this way:

using (IDataReader reader = this._dataLayer.ExecuteSQL(sqlStatement))
{

             List<UserInfo> list = new List<UserInfo>();
            while (reader.Read())
            {
                list.Add( UserController.GetUserByName(Int32.Parse(reader[0].ToString()), reader[1].ToString() ));           
            }
            
 }

return list;

It works. My only concern with it is that I have 2 database access for each record.

this statement does it: this._dataLayer.ExecuteSQL(sqlStatement))

 this one also: UserController.GetUserByName(Int32.Parse(reader[0].ToString()), reader[1].ToString()

 

Is there a better way of doing it. I'm using dnn  6.1 api

 

Thanks

 
New Post
4/21/2012 4:10 AM
 
   Glad to see your function works. As for the performance, I think it is not a problem. Anyway, you just execute a read sql statement which doesn't impact too much data records.

Over 20 + professional dnn modules for News Article, Store, Video Gallery, Photo Gallery, Ultra Flash Player,YouTube Video, Image Slide show, Skin Chameleon and much more from DnnModule.com
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to return UserInfo array?How to return UserInfo array?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out