Try Now
More in this section

Forums / Developing with Sitefinity / User List - Multiple Profiles SF 4.3

User List - Multiple Profiles SF 4.3

2 posts, 0 answered
  1. Jaime Weise
    Jaime Weise avatar
    120 posts
    02 Nov 2008
    07 Mar 2012
    Link to this post
    Use of multiple profiles 
    I have created a couple profiles. We have decided that the best way to go is to use the default profile for signup and then use a custom profile for managing properties of that type of profile. We have multiple profile types that we will be using. 

    Problems Problems Problems
    A problem arose when we realized that two profiles cannot be integrated to the same submit button. I can add both to the same page but they don't update when the default profile submit button is pressed. We decided that the it is not a big deal that there are two separate settings page to manage the multiple profiles for pages. However, when we use the user list we need access to both user profiles when it comes to databinding our values. 

    Need the best solution.
    What is the best way to manage this? I suppose we could inject a server script to get all the the users that fit our criteria and then put them in a repeater or gridview. It would be nice if we could easily inject the values of both profiles into the datasource of the current profile implementation so we could naturally just add more fields without making much repairs.
  2. Jaime Weise
    Jaime Weise avatar
    120 posts
    02 Nov 2008
    08 Mar 2012
    Link to this post
    Here is what I came up with.
    protected void Page_Load(object sender, EventArgs e)
        // Get an instance of UserManager
        var userManager = UserManager.GetManager();
        var pm = UserProfileManager.GetManager();
        var rm = new RoleManager();
        // Get a collection of all the users in the website
        var users = rm.GetUsersInRole("Professional");
        var data = new List<TempData>();
        int iter = 0;
        foreach (var user in users)
            if (user.CreationDate.AddSeconds(1) > user.LastModified) continue;
            var tempData = new TempData();
            // User default informaiton
            var defaultProfile = pm.GetUserProfile<SitefinityProfile>(user);
            tempData.FirstName = defaultProfile.FirstName;
            tempData.LastName = defaultProfile.LastName;
            // User Professional information
            var professional = pm.GetUserProfile(user, "Telerik.Sitefinity.Security.Model.professionalprofile");
            tempData.CompanyName = professional.GetValue("CompanyName").ToString();
        ListViewProfessionals.DataSource = data;
    protected class TempData
        public String FirstName { get; set; }
        public String LastName { get; set; }
        public String CompanyName { get; set; }

    Note the check at the start of the loop. The profiles seem to be lazy generated so if you create a user without actually going into the user properties. The code above will crash saying that the profile doesn't exist even if you added the custom profile type upon creation.
2 posts, 0 answered