public Role(BasicPersonRole org) : base(org) { organisationName = Organization.FromIdentity(this.OrganizationId).Name; personName = Person.FromIdentity(this.PersonId).Name; roleName = Enum.GetName(this.Type.GetType(), this.Type); geographyName = ""; if (RoleTypes.ClassOfRole(this.Type) == RoleClass.Local) { if (GeographyId > 0) { geographyName = Geography.FromIdentity(GeographyId).Name; } } }
private static void RecursiveAddInTreeOrder(List <Role> resultList, Dictionary <int, List <Role> > roleDictionary, int currentOrg, int level) { if (roleDictionary.ContainsKey(currentOrg)) { roleDictionary[currentOrg].Sort( delegate(Role r1, Role r2) { int res = 0; try { res = ((int)RoleTypes.ClassOfRole(r1.Type)).CompareTo((int)RoleTypes.ClassOfRole(r2.Type)); } catch { } try { if (res == 0) { res = hierarchicalSortOrder[r1.GeographyId].Order.CompareTo( hierarchicalSortOrder[r2.GeographyId].Order); } } catch { } if (res == 0) { res = r1.Type.CompareTo(r2.Type); } return(res); }); foreach (Role role in roleDictionary[currentOrg]) { role.Level = level; role.GeoLevel = hierarchicalSortOrder[role.GeographyId].Level; resultList.Add(role); } } Organizations children = Organization.FromIdentity(currentOrg).Children; foreach (Organization org in children) { RecursiveAddInTreeOrder(resultList, roleDictionary, org.OrganizationId, level + 1); } }
public BasicAuthority GetPersonAuthority(IHasIdentity person) { List <BasicPersonRole> systemRoles = new List <BasicPersonRole>(); List <BasicPersonRole> organizationRoles = new List <BasicPersonRole>(); List <BasicPersonRole> localRoles = new List <BasicPersonRole>(); using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); DbCommand command = GetDbCommand("SELECT " + personRoleFieldSequence + ConstructWhereClause("PersonRoles", person), connection); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { BasicPersonRole newPersonRole = ReadPersonRoleFromDataReader(reader); switch (RoleTypes.ClassOfRole(newPersonRole.Type)) { case RoleClass.System: systemRoles.Add(newPersonRole); break; case RoleClass.Organization: organizationRoles.Add(newPersonRole); break; case RoleClass.Local: localRoles.Add(newPersonRole); break; default: throw new InvalidOperationException("Invalid RoleTypeId (" + newPersonRole.Type + ") in database for PersonId " + person.Identity.ToString()); } } return(new BasicAuthority(person.Identity, systemRoles.ToArray(), organizationRoles.ToArray(), localRoles.ToArray())); } } }