I have 2 Tables that is m to n relationships between them. Roles, Moduls, ModulsInRoles. I get current user roles. IAnd I want to get these roles’ moduls. I tried to write something. But I cant success.
string[] roller = System.Web.Security.Roles.GetRolesForUser();
IEnumerable<TblModuller> moduller = null;
IEnumerable<TblModulsInRoles> moduls_in_roles = null;
foreach (var rol in roller)
{
moduls_in_roles = entity.TblModulsInRoles.Where(x => x.Roles.RoleName == rol);
foreach(var modul in moduls_in_roles)
{
//I dont know What should I write or this code is correct.
}
}
for example; My data is like this:
Admin Modul1
Admin Modul2
User Modul2
User Modul3
And I want to get this:
Modul1
Modul2
Modul3
What is the logic? and Is there some code example or tutorial about this topic.
Thanks.
Try This