c# - Filter users by roles -
i have regular mvc app standard business relationship controller. i've added couple fields userprofile class, looks this:
public class userprofile { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int userid { get; set; } public string username { get; set; } public string firstname { get; set; } public string lastname { get; set; } public string email { get; set; } public string address { get; set; } public string phone { get; set; } public string fullname { { homecoming firstname + " " + lastname; } } public int groupid { get; set; } [foreignkey("groupid")] public icollection<group> groups { get; set; } }
so, saying user can assigned multiple groups. (and in grouping class grouping can contain multiple users, obviously).
now, each user must in specific role. (admin, teacher, pupil etc.)
i've added roles back upwards next tutorial online this:
<rolemanager enabled="true" defaultprovider="simpleroleprovider"> <providers> <clear/> <add name="simpleroleprovider" type="webmatrix.webdata.simpleroleprovider, webmatrix.webdata"/> </providers> </rolemanager> <membership defaultprovider="simplemembershipprovider"> <providers> <clear/> <add name="simplemembershipprovider" type="webmatrix.webdata.simplemembershipprovider, webmatrix.webdata" /> </providers> </membership>
now want filter of users rolename. not have way that. ie. this. users.where(x=>x.rolename=="admin").select(x=>x.fullname)
(users
property of grouping class of type icollection<users>
). how roles without having class roles?
the asp.net membership has static roles class getusersinrole method, currentuser in httpcontext can tell roles active user in.
http://msdn.microsoft.com/en-us/library/system.web.security.roles.getusersinrole.aspx
http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.aspx
c# asp.net-mvc entity-framework asp.net-mvc-4 entity-framework-5
No comments:
Post a Comment