I have a model like below where PermissionGroup has 1-Many relationship with Permission and Permission and Roles have Many-Many relationship.
PermissionGroup 1-----* Permission *--------* Role
I have to be able to return JSON in the following format:
PermissionGroupId : 1,
PermissionGroupName : "Market",
Permissions : [
{PermissionId : 1, PermissionName : "Create"},
{PermissionId : 2, PermissionName : "Update"}
]
That will be asked for a specific RoleId.
Problem:
Since, PermissionGroup has no relation directly with Role so I cannot do a Where linq query. I could do the following but it is not returning desired result like above.
public JsonResult GetRolePermission(int roleid)
{
var list = con.PermissionGroups.Select(pg => new
{
PermissionGroupId = pg.PermissionGroupId,
PermissionGroupName = pg.PermissionGroupName,
Permissions = pg.Permissons.Select(pe => new
{
PermissionId = pe.PermissionId,
PermissionName = pe.PermissionName
})
})//Maybe do the where query here somehow like where(f => f.RoleId == roleid);
return Json(list);
}
Any suggestion is appreciated.
Rolesmember. Is it full? And what isroleid? How it is connected withPermissionGroups?RoleIdis primary identifier for theRoleentity. Please refer to the diagram I posted above for their relationships.