public List <ListPerson> GetData(string sortBy) { List <ListPerson> retval = new List <ListPerson>(); if (this.listedPersons != null) { People ppl = People.FromIdentities(this.listedPersons); Dictionary <int, List <BasicParticipation> > membershipTable = Participations.GetParticipationsForPeople(ppl, Participation.GracePeriod); Participations participationsToLoad = new Participations(); foreach (Person p in ppl) { if (membershipTable.ContainsKey(p.Identity)) { foreach (BasicParticipation bm in membershipTable[p.Identity]) { if (bm.OrganizationId == this.selectedOrgId) { Participation ms = Participation.FromBasic(bm); participationsToLoad.Add(ms); } } } } Participation.LoadPaymentStatuses(participationsToLoad); Dictionary <int, Participation> memberships = new Dictionary <int, Participation>(); foreach (Participation ms in participationsToLoad) { memberships[ms.Identity] = ms; } foreach (Person p in ppl) { ListPerson lp = new ListPerson(p); if (membershipTable.ContainsKey(p.Identity)) { foreach (BasicParticipation bm in membershipTable[p.Identity]) { if (bm.OrganizationId == this.selectedOrgId) { Participation ms = memberships[bm.MembershipId]; lp.JoinedDate = ms.MemberSince; lp.ExpiresDate = ms.Expires; lp.MembershipId = ms.Identity; retval.Add(lp); } } } } } PropertyInfo pi = typeof(ListPerson).GetProperty(sortBy); if (pi != null) { MemberInfo[] miA = pi.PropertyType.GetMember("CompareTo", MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); if (miA.Length > 0) { MethodInfo mi = (MethodInfo)miA[0]; retval.Sort( delegate(ListPerson p1, ListPerson p2) { return(Convert.ToInt32(mi.Invoke(pi.GetValue(p1, null), new[] { pi.GetValue(p2, null) }))); }); } } return(retval); }
public People FilterPeople(People rawList, AccessAspect aspect = AccessAspect.Participation) { if (aspect != AccessAspect.Participation && aspect != AccessAspect.PersonalData) { throw new ArgumentException(@"AccessAspect needs to reflect visibility of people data", "aspect"); } // Three cases: // 1) the current Position has system-level access. // 2) the current Position has org-level, but not system-level, access. // 3) the current Position has org-and-geo-level access. Dictionary <int, bool> orgLookup = new Dictionary <int, bool>(); Dictionary <int, bool> geoLookup = new Dictionary <int, bool>(); People result = new People(); // Org lookup will always be needed. Geo lookup may be needed for case 3. Organizations orgStructure = this.Organization.ThisAndBelow(); int[] orgIds = orgStructure.Identities; foreach (int orgId in orgIds) { orgLookup[orgId] = true; } orgLookup[Organization.Identity] = true; Dictionary <int, List <BasicParticipation> > membershipLookup = null; if (HasSystemAccess(AccessType.Read) || HasAccess(new Access(Organization, aspect, AccessType.Read))) { // cases 1 and 2: systemwide access, return everybody at or under the current Organization, // or org-wide read access (at least) to participant/personal data at current Organization // Optimization: Get all memberships in advance, without instantiating logic objects membershipLookup = Participations.GetParticipationsForPeople(rawList.Identities, 0); foreach (Person person in rawList) { // For each person, we must test the list of active memberships to see if one of // them is visible to this Authority - if it's a membership in an org at or below the // Authority object's organization if (membershipLookup.ContainsKey(person.Identity)) { List <BasicParticipation> list = membershipLookup[person.Identity]; foreach (BasicParticipation basicMembership in list) { if (orgLookup.ContainsKey(basicMembership.OrganizationId)) { // hit - this person has an active membership that makes them visible to this Authority result.Add(person); break; } } } } return(result); } // Case 3: Same as above but also check for Geography (in an AND pattern). if (this.Position == null) { // No access at all. That was an easy case! return(new People()); // return empty list } if (this.Position.Geography == null) { // Org-level position, but one that doesn't have access to personal data, apparently. return(new People()); // empty list again } if (!HasAccess(new Access(this.Organization, Position.Geography, aspect, AccessType.Read))) { // No people access for active position. Also a reasonably easy case. return(new People()); // also return empty list } Geographies geoStructure = this.Position.Geography.ThisAndBelow(); int[] geoIds = geoStructure.Identities; foreach (int geoId in geoIds) { geoLookup[geoId] = true; } geoLookup[Position.GeographyId] = true; // Optimization: Get all memberships in advance, without instantiating logic objects Dictionary <int, List <BasicParticipation> > personLookup = Participations.GetParticipationsForPeople(rawList.Identities, 0); foreach (Person person in rawList) { // For each person, we must test the list of active memberships to see if one of // them is visible to this Authority - if it's a membership in an org at or below the // Authority object's organization - and also test the person's Geography against // the list (lookup) of visible Geographies. We do Geographies first, because that test is // much cheaper. if (geoLookup[person.GeographyId]) { // Geography hit. Test Membership / Organization. List <BasicParticipation> list = personLookup[person.Identity]; foreach (BasicParticipation basicMembership in list) { if (orgLookup.ContainsKey(basicMembership.OrganizationId)) { // Organization hit - this person has an active membership that makes them visible to this Authority result.Add(person); } } } } return(result); }