public async Task <List <SelectionItem <string> > > GetUserRolesAsync(int userId) { using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { List <SelectionItem <string> > list = new List <SelectionItem <string> >(); UserDefinition user = await userDP.GetItemByUserIdAsync(userId); if (user != null) { using (RoleDefinitionDataProvider roleDP = new RoleDefinitionDataProvider()) { List <RoleDefinition> allRoles = roleDP.GetAllRoles(); foreach (Role r in user.RolesList) { RoleDefinition roleDef = (from a in allRoles where a.RoleId == r.RoleId select a).FirstOrDefault(); if (roleDef != null) { list.Add(new SelectionItem <string> { Text = roleDef.Name, Tooltip = roleDef.Description, Value = roleDef.Id }); } } } } return(list); } }
public List <RoleInfo> GetDefaultRoleList(bool Exclude2FA = false) { using (RoleDefinitionDataProvider roleDP = new RoleDefinitionDataProvider()) { List <RoleDefinition> allRoles = roleDP.GetAllRoles(); List <RoleInfo> roles; if (Exclude2FA) { roles = (from r in allRoles where r.RoleId != roleDP.GetUser2FARoleId() select new RoleInfo { RoleId = r.RoleId, Name = r.Name, Description = r.Description, PostLoginUrl = r.PostLoginUrl }).ToList(); } else { roles = (from r in allRoles select new RoleInfo { RoleId = r.RoleId, Name = r.Name, Description = r.Description, PostLoginUrl = r.PostLoginUrl }).ToList(); } return(roles); } }