示例#1
0
        public static People GetActivists(Organization organization, Geography geography)
        {
            People people = new People();

            // Expensive op:
            BasicPersonRole[] basicPersonRoles =
                SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies(organization.ThisAndBelow().Identities,
                                                                                    geography.ThisAndBelow().Identities);

            Dictionary <int, bool> lookup = new Dictionary <int, bool>();

            foreach (BasicPersonRole basicRole in basicPersonRoles)
            {
                if (basicRole.Type == RoleType.LocalActive || basicRole.Type == RoleType.LocalLead ||
                    basicRole.Type == RoleType.LocalDeputy)
                {
                    if (!lookup.ContainsKey(basicRole.PersonId))
                    {
                        people.Add(Person.FromIdentity(basicRole.PersonId));
                        lookup[basicRole.PersonId] = true;
                    }
                }
            }

            people.Sort();
            return(people);
        }
示例#2
0
        public static string GetRecipientCount(int recipientTypeId, int geographyId)
        {
            int personCount = 0;

            AuthenticationData authData  = GetAuthenticationDataAndCulture();
            Geography          geography = Geography.FromIdentity(geographyId);
            Geographies        geoTree   = geography.ThisAndBelow();
            Organizations      orgTree   = authData.CurrentOrganization.ThisAndBelow();

            switch (recipientTypeId)
            {
            case 0:     // "Select one"
                personCount = 0;
                break;

            case 1:     // Regulars
                personCount = orgTree.GetMemberCountForGeographies(geoTree);
                break;

            case 2:     // Agents
                personCount = Activists.GetCountForGeography(geography);
                break;

            // TODO: Dynamic membership types

            case 101:     // Officers
                personCount = orgTree.GetRoleHolderCountForGeographies(geoTree);
                break;

            case 102:            // Volunteers
                personCount = 0; // TODO
                break;

            default:
                throw new NotImplementedException();
            }

            string result;

            string[] resources = Resources.Pages.Comms.SendMassMessage_RecipientCount.Split('|');

            switch (personCount)
            {
            case 0:
                result = resources[0];
                break;

            case 1:
                result = resources[1];
                break;

            default:
                result = String.Format(resources[2], personCount);
                break;
            }

            return(result);
        }
示例#3
0
        public static People FromOrganizationAndGeography(Organization organization, Geography geography)
        {
            Geographies geoTree = geography.ThisAndBelow();

            // First, get list of people in the geography, then filter on memberships

            BasicPerson[] people = SwarmDb.GetDatabaseForReading().GetPeopleInGeographies(geoTree.Identities);

            // Filter on memberships

            return(People.LogicalOr(FilterByMembership(people, organization), FilterByApplicant(people, organization)));
        }
示例#4
0
        public static People FromOrganizationAndGeographyWithPattern(Organization organization, Geography geography,
                                                                     string pattern)
        {
            Geographies geoTree = geography.ThisAndBelow();

            pattern = pattern.Trim();
            if (pattern.Length == 0)
            {
                return(FromOrganizationAndGeography(organization, geography));
            }
            if (pattern.Length < 3)
            {
                // too short pattern! Return empty set.
                return(new People());
            }

            // First, get list of people in the geography, then filter on memberships

            BasicPerson[] candidates =
                SwarmDb.GetDatabaseForReading().GetPeopleInGeographiesWithPattern(geoTree.Identities, pattern);

            return(People.LogicalOr(FilterByMembership(candidates, organization), FilterByApplicant(candidates, organization)));
        }
示例#5
0
        public static Activists FromGeography(Geography geography)
        {
            Geographies geographies = geography.ThisAndBelow();

            return(new Activists(SwarmDb.GetDatabaseForReading().GetActivistPersonIds(geographies.Identities)));
        }
示例#6
0
        public static int GetCountForGeography(Geography geography)
        {
            Geographies geographies = geography.ThisAndBelow();

            return(SwarmDb.GetDatabaseForReading().GetActivistCountForGeographies(geographies.Identities));
        }