User List - Multiple Profiles SF 4.3
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.
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();
data.Add(tempData);
ListViewProfessionals.DataSource = data;
ListViewProfessionals.DataBind();
protected
class
TempData
public
String FirstName
get
;
set
;
public
String LastName
get
;
set
;
public
String CompanyName
get
;
set
;