+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add/Edit Users: Adding additional functionality

Add/Edit Users: Adding additional functionality

6 posts, 1 answered
  1. Martin
    Martin avatar
    2 posts
    Registered:
    25 Aug 2010
    26 Aug 2010
    Link to this post
    First of all, I'd like to congratulate Telerik on this community. I've come here countless times and found an answer without posting. Something has to be said for that.

    However this time, I'm in a crunch and I cannot find an answer. I'm adding custom fields to users in the backend using properties tag in the web.config. However, I need to retrieve this new user information in the front end of the site against these properties pretty quickly. Since this site will have hundreds of users, I cannot retrieve all the users into a collection and then individually test if the property meets my criteria.

    I was thinking that I can override the SaveUser and Create buttons on the Users.aspx to insert my custom fields into a table, thus I can retrieve the data in the front end quickly using Linq. I'm not quite clear how these buttons are wired up since they don't have an OnClick or OnCommand events in the codebehind..

    Or is there a way to do this with just the property meta data? Possibly something like: Membership.FindUsersByProperty([name], [value]);

    Thanks in advance,
    Martin
  2. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    HI Martin,

    There is basically no API to query the Profile, however this might help:

    var usersWithPropertyValue = Membership.GetAllUsers().Cast<MembershipUser>()
        .Select(user => ProfileBase.Create(user.UserName, true))
        .Where(profile => ((int)profile["propertyName"]) == 10 /*insert your profile criteria here*/)
        .ToList();

    Or you can create a Custom Profile Provider and add your own means of querying the profile container table and getting the appropriate userIDs. Perhaps query the database directly.

    Best,

    G
    Answered
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    26 Aug 2010
    Link to this post
    Hi George ,

    The profiledata is automatically persisted into the database and you do not need to subscribe for click events of any button. You only have to retrieve this data in your public control . ProfileBase.Create() gives you direct access to the user and you do not have to loop through a collection. The ProfileBase object has two methods GetPropertyValue and SetPropertyValue that you can use to get/set data. You can gather more information at MSDN.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    26 Aug 2010
    Link to this post
    Hi Ivan,

    The issue that Martin is discussing is basically how to query the Profiles of the users to get those whose properties match certain values i.e: get all users who live in City A. For this, I don't think Martin has any other option but looping through the profiles and check the properties values using the GetPropertyValue function that you have mentioned. Martin is actually worried about the performance when it comes to loading thousands of users profiles into memory and looping through them.

    I suppose there is a way to query the database directly instead of using the profile API. What is your input about this issue Ivan?

    Best,

    G
  5. Martin
    Martin avatar
    2 posts
    Registered:
    25 Aug 2010
    26 Aug 2010
    Link to this post
    Hi George,

    Yes you hit the nail on the head. I'm trying to avoid loading all the user profiles and then going through them individually evaluating each property. The code you have posted is what I came up with also.

    And yes, one solution would be to just create my own membership provider. However, the Sitefinity provider serves my purpose completely except for this one function. I'll use this if there is no other option.

    I would like to hear from Ivan if can directly access the properties or some other way I can query against all the users.


    Thanks for your input,
    Martin.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    26 Aug 2010
    Link to this post
    Hello Martin,

    You can use C# indexer or Linq Take and Skip method - allows to specify how many items will be fetched. You can use paging and bind the control per page in case there are many records.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 1 answered