public List <SecurityRole> GetRoles() { var list = new List <SecurityRole>(); var qe = new QueryExpression("role") { Criteria = new FilterExpression(), ColumnSet = new ColumnSet(true) }; qe.Criteria.AddCondition("parentroleid", ConditionOperator.Null); var roles = service.RetrieveMultiple(qe).Entities; foreach (var role in roles) { var sr = new SecurityRole { Id = role.Id, Name = role["name"].ToString(), Privileges = new List <Privilege>() }; var request = new RetrieveRolePrivilegesRoleRequest { RoleId = role.Id }; var response = (RetrieveRolePrivilegesRoleResponse)service.Execute(request); foreach (var roleprivilege in response.RolePrivileges) { sr.Privileges.Add(new Privilege { Id = roleprivilege.PrivilegeId, Depth = roleprivilege.Depth }); } list.Add(sr); } return(list); }
public List<SecurityRole> GetRoles() { var list = new List<SecurityRole>(); var qe = new QueryExpression("role") {Criteria = new FilterExpression(), ColumnSet = new ColumnSet(true)}; qe.Criteria.AddCondition("parentroleid", ConditionOperator.Null); var roles = service.RetrieveMultiple(qe).Entities; foreach (var role in roles) { var sr = new SecurityRole { Id = role.Id, Name = role["name"].ToString(), Privileges = new List<Privilege>() }; var request = new RetrieveRolePrivilegesRoleRequest { RoleId = role.Id }; var response = (RetrieveRolePrivilegesRoleResponse) service.Execute(request); foreach (var roleprivilege in response.RolePrivileges) { sr.Privileges.Add(new Privilege { Id = roleprivilege.PrivilegeId, Depth = roleprivilege.Depth }); } list.Add(sr); } return list; }