public static List <RbacRole> GetUserAllRoles(int userid) { List <RbacRole> retList = new List <RbacRole>(); List <RbacRole> allRoles = RBAC.GetAllRoles(); List <UserRoleMap> allUsrRoleMap = RBAC.GetAllUserRoleMaps(); //return only roles which are mapped to this user. retList = (from role in allRoles join map in allUsrRoleMap on role.RoleId equals map.RoleId where map.UserId == userid select role).Distinct().ToList(); return(retList); }
public static List <RbacPermission> GetUserAllPermissions(int userId) { List <RbacPermission> retList = (List <RbacPermission>)DanpheCache.Get("RBAC-UserPermissions-UserId" + userId); if (retList == null) { var isUsrSysAdmin = (from usRole in RBAC.GetAllUserRoleMaps() where usRole.UserId == userId join role in RBAC.GetAllRoles() on usRole.RoleId equals role.RoleId where role.IsSysAdmin == true select role).Count() > 0; //return all permissions if current user is systemadmin. if (isUsrSysAdmin) { retList = RBAC.GetAllPermissions(); } else { retList = (from urole in RBAC.GetAllUserRoleMaps() where urole.UserId == userId && urole.IsActive == true join role in RBAC.GetAllRoles() on urole.RoleId equals role.RoleId join rolePmap in RBAC.GetAllRolePermissionMaps() on urole.RoleId equals rolePmap.RoleId join perm in RBAC.GetAllPermissions() on rolePmap.PermissionId equals perm.PermissionId where rolePmap.IsActive == true join app in RBAC.GetAllApplications() on perm.ApplicationId equals app.ApplicationId where app.IsActive == true select perm).ToList(); } DanpheCache.Add("RBAC-UserPermissions-UserId" + userId, retList, cacheExpiryMinutes); } return(retList); }