Ejemplo n.º 1
0
        /// <summary>
        /// find a legislator by name.
        /// Note: the name is a case insensitive substring
        /// to make finding the legislator more likely.
        /// Note: This method lets you know if there are more
        /// than one match.
        /// </summary>
        /// <param name="nom"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int FindLegislator(string nom, out string msg)
        {
            string nom_lower = nom.ToLower();
            string NomFound  = "";

            msg = "";
            int Total = 0;

            if (nom == null || nom == "")
            {
                msg = "Invalid legislator name";
                return(Total);
            }
            try
            {
                if (this.Leges == null || Leges.Count <= 0)
                {
                    msg = "Legislative info not available.";
                    return(0);
                }
                int n = this.Leges.Count;
                for (int i = 0; i < n; i++)
                {
                    OneLege one = this.Leges[i];
                    if (one != null && one.People != null)
                    {
                        int m = one.People.Count;
                        for (int j = 0; j < m; j++)
                        {
                            string s = one.People[j].Name.ToLower();
                            if (s != null && s.Contains(nom_lower))
                            {
                                Total++;
                                NomFound = one.People[j].Name;
                            }
                        }
                    }
                }
                if (Total <= 0)
                {
                    msg = "No legislator with the name " + nom;
                }
                else if (Total == 1)
                {
                    msg = $"{NomFound} found.";
                }
                else
                {
                    msg = $"There are {Total} legislators with names containing \"{nom}\".";
                }
            }
            catch (System.Exception)
            {
            }
            return(Total);
        }
Ejemplo 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);
        }