Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Get a list of users with particular profile properties

I'm using ASP.NET MVC 1 and I have added a custom Profile class using the WebProfile Builder VS add-in (found here: http://code.msdn.microsoft.com/WebProfileBuilder/Release/ProjectReleases.aspx?ReleaseId=980).

On one of my forms I want a drop-down list of all users who share a specific profile value in common.

I can see that I can get a list of all users using:

Membership.GetAllUsers()

However I cannot see how to get all users who have a specific profile value, which in my case is CellId.

Am I approaching this in the right way? I have used membership roles to define which users are administrators etc, but profiles seems like the right place to group users.

Any pointers both in specifics of how to access the user list but also comments on whether am I pursuing the right avenue here would be greatly appreciated.

Many thanks, Sam

like image 870
Sam Huggill Avatar asked Oct 15 '22 07:10

Sam Huggill


1 Answers

There is no query API for Profile, but this may give you some guidance:

var usersWithNonZeroCounter = Membership.GetAllUsers().Cast<MembershipUser>()
    .Where(user => true /*insert your user criteria here*/)
    .Select(user => ProfileBase.Create(user.UserName, true))
    .Where(profile => ((int)profile["counter"]) > 0 /*insert your profile criteria here*/)
    .ToList();
like image 187
Sky Sanders Avatar answered Oct 18 '22 13:10

Sky Sanders