/// <summary>
        /// get people in all legislatures for a given state
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task <LegeSet> GetStatePeopleAsync(string state)
        {
            LegeSet inf = null;

            try
            {
                var graphQLRequest = new GraphQLRequest();

                string queryJurisdictionFixed = FixQueryQuotes(QsStateLeges);
                //
                // note: GraphQL "query variable" feature should be able to be used
                // but I havent got that working yet.  Maybe it's not implemented yet
                // for OpenStates.
                queryJurisdictionFixed = queryJurisdictionFixed.Replace("$state", state);
                graphQLRequest.Query   = queryJurisdictionFixed;
                var response = await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false);

                int NumLege = response.Data.jurisdiction.organizations.edges.Count;
                inf = new LegeSet(state);
                for (int i = 0; i < NumLege; i++)
                {
                    string OneLegeName = response.Data.jurisdiction.organizations.edges[i].node.name.ToString();
                    string OneLegeId   = response.Data.jurisdiction.organizations.edges[i].node.id.ToString();
                    int    q           = response.Data.jurisdiction.organizations.edges[i].node.children.edges.Count;
                    for (int k = 0; k < q; k++)
                    {
                        string OneName = response.Data.jurisdiction.organizations.edges[i].node.children.edges[k].node.name;
                        string OneID   = response.Data.jurisdiction.organizations.edges[i].node.children.edges[k].node.id;

                        Newtonsoft.Json.Linq.JArray peeps = await GetPeopleByOrgIDAllAsync(OneID, null, null);

                        List <OnePerson> PeopleNames;
                        if (peeps != null)
                        {
                            int m = peeps.Count;
                            PeopleNames = new List <OnePerson>(m);
                            for (int j = 0; j < m; j++)
                            {
                                string    NomJ = peeps[j]["node"]["name"].ToString();
                                OnePerson p    = new OnePerson(NomJ);
                                PeopleNames.Add(p);
                            }
                        }
                        else
                        {
                            PeopleNames = new List <OnePerson>();
                        }
                        inf.AddLege(OneName, OneID, PeopleNames);
                    }
                }
            }
            catch (System.Exception)
            { }
            return(inf);
        }
Exemplo n.º 2
0
        /// <summary>
        /// summarize the legislature into a text string.
        /// </summary>
        /// <returns></returns>
        public string SummarizeLeges()
        {
            string Msg = "";

            try
            {
                if (Leges != null)
                {
                    int n = Leges.Count;
                    for (int i = 0; i < n; i++)
                    {
                        OneLege leg     = Leges[i];
                        string  LegeNom = leg.LegeName;
                        if (LegeNom != null)
                        {
                            string s = $"----- {this.State} {LegeNom} -----\n";
                            Msg += s;
                            if (leg.People != null)
                            {
                                int m = leg.People.Count;
                                for (int j = 0; j < m; j++)
                                {
                                    OnePerson p = leg.People[j];
                                    if (p != null && p.Name != null)
                                    {
                                        string PersonName = p.Name;
                                        string s2         = $"  {PersonName}\n";
                                        Msg += s2;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception)
            {
            }
            return(Msg);
        }