Example #1
0
        public static Uri GetPrivacyPageUri(string state)
        {
            if (!StateCache.IsValidStateCode(state))
            {
                return(GetSiteUri("Privacy.aspx"));
            }
            var qsc = new QueryStringCollection();

            AddNonEmptyParm(qsc, "State", state);
            return(GetStateUri(state, "Privacy.aspx", qsc));
        }
 private void FillInTitles()
 {
     ElectionTitle.InnerText = _ElectionDescription;
     if (StateCache.IsValidStateCode(_StateCode))
     {
         ElectionSubTitle.InnerText = Elections.GetElectoralClassDescription(_ElectionKey);
     }
     else
     {
         ElectionSubTitle.Visible = false;
     }
 }
Example #3
0
        private void HandlePoliticianIssuePage()
        {
            var stateCode = Politicians.GetStateCodeFromKey(GetQueryParm("Id"));

            if (StateCache.IsValidStateCode(stateCode))
            {
                NormalizedUri = UrlManager.GetPoliticianIssuePageUri(stateCode,
                                                                     GetQueryParm("Id"), GetQueryParm("Issue"));
            }
            else
            {
                ErrorMessage = "Invalid StateCode";
            }
        }
Example #4
0
        private void HandleElectedPage()
        {
            var stateCode = UrlManager.FindStateCode();

            if (StateCache.IsValidStateCode(stateCode))
            {
                NormalizedUri = UrlManager.GetElectedPageUri(stateCode,
                                                             GetQueryParm("Congress"), GetQueryParm("StateSenate"),
                                                             GetQueryParm("StateHouse"), GetQueryParm("County"));
            }
            else
            {
                ErrorMessage = "Invalid_StateCode";
            }
        }
Example #5
0
        public static string FormatLegislativeDistrictsFromQueryStringForHeading(bool useSpans = false)
        {
            string subtitle;

            if (StateCache.IsValidStateCode(QueryState))
            {
                subtitle = (useSpans
            ? "<span class=\"districts-head\">For address in:</span>"
            : "<span class=\"districtsHead\">For address in:</span><br />") +
                           FormatLegislativeDistrictsFromQueryString(useSpans ? null : "<br /");
            }
            else
            {
                subtitle = "for any address in the United States";
            }
            return(subtitle);
        }
 protected override void OnPreLoad(EventArgs e)
 {
     base.OnPreLoad(e);
     PartyKey       = ViewStatePartyKey;
     PartyKeyExists = Parties.PartyKeyExists(PartyKey);
     if (PartyKeyExists)
     {
         PartyName           = PageCache.Parties.GetPartyName(PartyKey);
         PartyCode           = PageCache.Parties.GetPartyCode(PartyKey);
         StateCode           = PageCache.Parties.GetStateCode(PartyKey);
         IsPartyMajor        = PageCache.Parties.GetIsPartyMajor(PartyKey);
         StateCodeIsNonState = !StateCache.IsValidStateCode(StateCode);
     }
     else if (!IsSignedIn) // if not signed in, dump to sign in pageName
     {
         RedirectToSignInPage();
     }
 }
Example #7
0
        private static List <LinkInfo> GetUpcomingLinks(string stateCode)
        {
            var linkList = new List <LinkInfo>();

            if (StateCache.IsValidStateCode(stateCode))
            {
                var table = Elections.GetFutureViewableDisplayDataByStateCode(stateCode);
                linkList.AddRange(
                    table.Select(
                        row =>
                        new LinkInfo(row)
                {
                    HRef = UrlManager.GetElectionPageUri(row.ElectionKey)
                }));
            }

            return(linkList);
        }
Example #8
0
        private static void CheckForFatalCredentialingProblems(string usernameEntered)
        {
            switch (UserSecurityClass)
            {
            case MasterSecurityClass:
                // no additional info needed
                break;

            case StateAdminSecurityClass:
                if (!StateCache.IsValidStateCode(UserStateCode))
                {
                    HandleCredentialingInconsistency(usernameEntered, "Invalid StateCode");
                }
                break;

            case CountyAdminSecurityClass:
                if (!Counties.StateCodeCountyCodeExists(UserStateCode, UserCountyCode))
                {
                    HandleCredentialingInconsistency(usernameEntered, "Invalid CountyCode");
                }
                break;

            case LocalAdminSecurityClass:
                if (!LocalDistricts.StateCodeLocalKeyExists(UserStateCode, UserLocalKey))
                {
                    HandleCredentialingInconsistency(usernameEntered, "Invalid LocalKey");
                }
                break;

            case PartySecurityClass:
                if (!Parties.PartyKeyExists(UserPartyKey))
                {
                    HandleCredentialingInconsistency(usernameEntered, "Invalid PartyKey");
                }
                break;

            case PoliticianSecurityClass:
                // no additional info needed --
                // they couldn't get this far without a valid politician key
                break;
            }
        }
Example #9
0
 public static Uri GetOfficialsPageUri(string report, string county = null, string local = null)
 {
     if (report != null && StateCache.IsValidStateCode(report))
     {
         var qsc = new QueryStringCollection();
         AddNonEmptyParm(qsc, "State", report);
         AddNonEmptyParm(qsc, "Report", report);
         AddNonEmptyParm(qsc, "County", county);
         AddNonEmptyParm(qsc, "Local", local);
         return(GetStateUri(report, "Officials.aspx", qsc));
     }
     else
     {
         var qsc = new QueryStringCollection();
         AddNonEmptyParm(qsc, "Report", report);
         return(HttpContext.Current == null
   ? GetSiteUri("Officials.aspx", qsc)
   : GetStateUri(G.State_Code(), "Officials.aspx", qsc));
     }
 }
Example #10
0
        private void HandleIssue2Page()
        {
            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();

            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            if (StateCache.IsValidStateCode(stateCode) && !string.IsNullOrEmpty(electionKey))
            {
                NormalizedUri = UrlManager.GetIssue2PageUri(stateCode, electionKey,
                                                            GetQueryParm("Congress"), GetQueryParm("StateSenate"),
                                                            GetQueryParm("StateHouse"), GetQueryParm("County"), GetQueryParm("Office"));
            }
            else
            {
                ErrorMessage =
                    "Invalid_ElectionKey|State|Congress|StateSenate|StateHouse|County";
            }
        }
Example #11
0
        public static ElectoralClass Electoral_Class(string stateCode, string countyCode,
                                                     string localCode)
        {
            if ((!string.IsNullOrEmpty(localCode)) && (!string.IsNullOrEmpty(countyCode)) &&
                (!string.IsNullOrEmpty(stateCode)))
            {
                return(ElectoralClass.Local);
            }

            if ((!string.IsNullOrEmpty(countyCode)) && (!string.IsNullOrEmpty(stateCode)))
            {
                return(ElectoralClass.County);
            }

            if (!string.IsNullOrEmpty(stateCode))
            {
                switch (stateCode)
                {
                case "PP":
                case "US":
                case "U1":
                    return(ElectoralClass.USPresident);

                case "U2":
                    return(ElectoralClass.USSenate);

                case "U3":
                    return(ElectoralClass.USHouse);

                case "U4":
                    return(ElectoralClass.USGovernors);

                default:
                    return(StateCache.IsValidStateCode(stateCode)
              ? ElectoralClass.State
              : ElectoralClass.All);
                }
            }

            return(ElectoralClass.Unknown);
        }
Example #12
0
        public static string FindStateCode()
        {
            // This is a replacement for db.State_Code() because in this context
            // we are only dealing with public pages. It is a rework of db.Domain_DataCode_This()
            var stateCode = HttpContext.Current.Request.QueryString["State"];

            if (string.IsNullOrEmpty(stateCode))
            {
                stateCode = HttpContext.Current.Request.QueryString["Data"];
            }
            if (string.IsNullOrEmpty(stateCode))
            {
                stateCode = GetStateCodeFromHostName(GetCurrentHostName());
            }
            stateCode = stateCode.ToUpper();
            if (!StateCache.IsValidStateCode(stateCode))
            {
                stateCode = string.Empty;
            }
            return(stateCode);
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Report.SignedInReportUser != ReportUser.Public)
            {
                this.IncludeCss("~/css/MainCommon.css");
                this.IncludeCss("~/css/SecondaryCommon.css");
                this.IncludeCss("~/css/All.css");
                this.IncludeCss("~/css/Officials.css");
            }

            if (HasUrlError)
            {
                InnerContent.Controls.Clear();
                var p = new HtmlP().AddTo(InnerContent, "not-found-error");
                new LiteralControl($"We could not show the information you requested: {UrlError}").AddTo(p);
                return;
            }

            _StateCode  = QueryReport;
            _CountyCode = Empty;
            _LocalKey   = Empty;
            if (IsNullOrWhiteSpace(_StateCode))
            {
                _StateCode = QueryState;
            }
            if (StateCache.IsValidStateCode(_StateCode))
            {
                _CountyCode = QueryCounty;
                _LocalKey   = QueryLocal;
            }

            _ElectoralClass = Offices.GetElectoralClass(_StateCode, _CountyCode, _LocalKey);

            AnalyzeElectoralClass();
            var report = OfficialsReportResponsive.GetReport(_StateCode, _CountyCode, _LocalKey);

            report.AddTo(ReportPlaceHolder);
        }
Example #14
0
 private static string StateCode_Domain_This()
 {
     return(StateCache.IsValidStateCode(Domain_DataCode_This())
 ? Domain_DataCode_This()
 : string.Empty);
 }
Example #15
0
        private void HandlePagesWithOnlyStateCode()
        {
            var stateCode = UrlManager.FindStateCode();

            if (string.IsNullOrEmpty(stateCode) || StateCache.IsValidStateCode(stateCode))
            {
                switch (OriginalUri.AbsolutePath.ToLower())
                {
                case "/":
                case "/default.aspx":
                    NormalizedUri = UrlManager.GetDefaultPageUri(stateCode);
                    break;

                case "/aboutus.aspx":
                    NormalizedUri = UrlManager.GetAboutUsPageUri(stateCode);
                    break;

                case "/contactus.aspx":
                    NormalizedUri = UrlManager.GetContactUsPageUri(stateCode);
                    break;

                case "/donate.aspx":
                    NormalizedUri = UrlManager.GetDonatePageUri(stateCode);
                    break;

                case "/forcandidates.aspx":
                    NormalizedUri = UrlManager.GetForCandidatesPageUri(stateCode);
                    break;

                case "/forresearch.aspx":
                    NormalizedUri = UrlManager.GetForResearchPageUri(stateCode);
                    break;

                case "/forpartners.aspx":
                    NormalizedUri = UrlManager.GetForPartnersPageUri(stateCode);
                    break;

                case "/forpoliticalparties.aspx":
                    NormalizedUri = UrlManager.GetForPoliticalPartiesPageUri(stateCode);
                    break;

                case "/forelectionauthorities.aspx":
                    NormalizedUri = UrlManager.GetForElectionAuthoritiesPageUri(stateCode);
                    break;

                case "/forvolunteers.aspx":
                    NormalizedUri = UrlManager.GetForVolunteersPageUri(stateCode);
                    break;

                case "/forvoters.aspx":
                    NormalizedUri = UrlManager.GetForVotersPageUri(stateCode);
                    break;

                case "/issuelist.aspx":
                    NormalizedUri = UrlManager.GetIssueListPageUri(stateCode);
                    break;

                case "/privacy.aspx":
                    NormalizedUri = UrlManager.GetPrivacyPageUri(stateCode);
                    break;
                }
            }
            else
            {
                ErrorMessage = "Invalid_StateCode";
            }
        }
Example #16
0
        public static string LookupUpEmailSourceCode(string sourceCode)
        {
            var sourceType = sourceCode[0];
            var subType    = sourceCode[1];
            var hyphenPos  = sourceCode.IndexOf('-');
            var stateCode  = Empty;

            if (hyphenPos <= 0 || hyphenPos > 2 || sourceCode.Length < hyphenPos + 2)
            {
                return(null);
            }

            switch (sourceType)
            {
            case 'S':
            case 'C':
            case 'L':
                if (sourceCode.Length < 5)
                {
                    return(null);
                }
                if (subType != 'P' && subType != 'A')
                {
                    return(null);
                }
                stateCode = sourceCode.Substring(hyphenPos + 1, 2);
                hyphenPos = 4;
                if (!StateCache.IsValidStateCode(stateCode))
                {
                    return(null);
                }
                break;

            case 'P':
                if (subType != 'M' && subType != 'C' && subType != 'S' && subType != 'V')
                {
                    return(null);
                }
                break;

            case 'A':
            case 'Z':
            case 'O':
                break;

            default:
                return(null);
            }

            var idString = sourceCode.Substring(hyphenPos + 1);

            if (!int.TryParse(idString, out var id) && sourceType != 'S')
            {
                return(null);
            }

            switch (sourceType)
            {
            case 'S':
                switch (subType)
                {
                case 'P':
                    return(States.GetContactEmail(stateCode));

                case 'A':
                    return(States.GetAltEmail(stateCode));
                }
                break;

            case 'C':
                switch (subType)
                {
                case 'P':
                    return(Counties.GetContactEmail(stateCode, idString));

                case 'A':
                    return(Counties.GetAltEmail(stateCode, idString));
                }
                break;

            case 'L':
                switch (subType)
                {
                case 'P':
                    return(LocalDistricts.GetContactEmail(stateCode, idString));

                case 'A':
                    return(LocalDistricts.GetAltEmail(stateCode, idString));
                }
                break;

            case 'P':
                switch (subType)
                {
                case 'M':
                    return(Politicians.GetEmailById(id));

                case 'C':
                    return(Politicians.GetCampaignEmailById(id));

                case 'S':
                    return(Politicians.GetStateEmailById(id));

                case 'V':
                    return(Politicians.GetEmailVoteUSAById(id));
                }
                break;

            case 'A':
                return(Addresses.GetEmailById(id));

            case 'Z':
                return(PartiesEmails.GetPartyEmailById(id));

            case 'O':
                return(OrganizationContacts.GetEmailByContactId(id));
            }

            return(null);
        }
Example #17
0
        public static DonorInfo ExtractDonorInfoFromMsg(Stream stream)
        {
            var info    = new DonorInfo();
            var message = new Storage.Message(stream);

            if (message.BodyText == null)
            {
                throw new VoteException("BodyText missing from message");
            }
            var lines = message.BodyText.NormalizeNewLines()
                        .Split('\n')
                        .Select(l => l.Trim())
                        .ToList();

            info.IsReversal = lines.Any(l => l.Contains("reverse their charge"));

            var dateTimeLine = lines.FirstOrDefault(l => DonorDateTimeRegex.IsMatch(l));

            if (dateTimeLine == null)
            {
                throw new VoteException("Could not find date and time");
            }
            var match      = DonorDateTimeRegex.Match(dateTimeLine);
            var parsedDate = match.Groups["date"].Value;
            var parsedTime = match.Groups["time"].Value;

            if (!DateTime.TryParse(parsedDate + " " + parsedTime, out info.Date))
            {
                throw new VoteException("Could not parse date and time");
            }

            if (!info.IsReversal)
            {
                var amountLine = lines.FirstOrDefault(l => DonorAmountRegex.IsMatch(l));
                if (amountLine == null)
                {
                    throw new VoteException("Could not find amount");
                }
                match = DonorAmountRegex.Match(amountLine);
                var parsedAmount = match.Groups["amount"].Value;
                if (!decimal.TryParse(parsedAmount, out info.Amount))
                {
                    throw new VoteException("Could not parse amount");
                }
            }

            var billingInfoIndex = lines.FindIndex(l => l == "Billing Information");

            if (billingInfoIndex < 0)
            {
                throw new VoteException("Could not find Billing Information");
            }
            // Old format : there is a "+++" line after Billing Information that starts the
            // "real" billing info
            var plusesIndex = lines.FindIndex(billingInfoIndex + 1, l => l == "+++");
            int billingInfoTerminatorIndex;

            if (plusesIndex >= 0) // old format
            {
                billingInfoIndex = plusesIndex;
                // Billing Information is delimited by a line of all "="
                billingInfoTerminatorIndex = lines.FindIndex(billingInfoIndex + 1,
                                                             l => l.All(c => c == '='));
            }
            else // new format
            {
                // Billing Information is delimited by a blank line
                billingInfoTerminatorIndex = lines.FindIndex(billingInfoIndex + 1,
                                                             string.IsNullOrWhiteSpace);
            }
            if (billingInfoTerminatorIndex < 0)
            {
                throw new VoteException("Could not find Billing Information delimiter");
            }
            var billingInfo = lines.Skip(billingInfoIndex + 1)
                              .Take(billingInfoTerminatorIndex - billingInfoIndex - 1)
                              .Where(l => !string.IsNullOrWhiteSpace(l))
                              .ToList();

            // assume last line is email
            var email = billingInfo.Count > 0
        ? billingInfo[billingInfo.Count - 1].Replace("Email: ", string.Empty)
        : null;

            if (!Validation.IsValidEmailAddress(email))
            {
                throw new VoteException("Could not find Email");
            }
            info.Email = email;
            billingInfo.RemoveAt(billingInfo.Count - 1);

            if (!info.IsReversal)
            {
                // assume first line is name
                if (billingInfo.Count == 0)
                {
                    throw new VoteException("Could not find Name");
                }
                info.FullName = billingInfo[0];
                billingInfo.RemoveAt(0);
                var parsedName = info.FullName.ParseName();
                if (string.IsNullOrWhiteSpace(parsedName.First) ||
                    string.IsNullOrWhiteSpace(parsedName.Last))
                {
                    throw new VoteException("Could not parse Name");
                }
                info.FirstName = parsedName.First;
                info.LastName  = parsedName.Last;

                // find the city, state zip line
                var cityIndex = billingInfo.FindLastIndex(l => DonorCityRegex.IsMatch(l));
                if (cityIndex < 0)
                {
                    throw new VoteException("Could not find City, State Zip");
                }
                match          = DonorCityRegex.Match(billingInfo[cityIndex]);
                info.City      = match.Groups["city"].Value;
                info.StateCode = match.Groups["state"].Value;
                if (!StateCache.IsValidStateCode(info.StateCode))
                {
                    // might be state name
                    info.StateCode = StateCache.GetStateCode(info.StateCode);
                    if (!StateCache.IsValidStateCode(info.StateCode))
                    {
                        throw new VoteException("Invaid state or state code");
                    }
                }
                info.Zip5 = match.Groups["zip5"].Value;
                info.Zip4 = match.Groups["zip4"].Value;

                // everything before city, state zip is address
                info.Address = string.Join(", ", billingInfo.Take(cityIndex));

                // last remaining line is assumed to be phone if it contains any digits
                info.Phone = billingInfo.Skip(cityIndex + 1)
                             .LastOrDefault() ?? string.Empty;
                info.Phone = info.Phone.Replace("Phone: ", string.Empty);
                if (!info.Phone.Any(char.IsDigit))
                {
                    info.Phone = string.Empty;
                }
            }

            return(info);
        }
Example #18
0
        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);
            StateCode       = FindStateCode();
            CountyCode      = FindCountyCode();
            LocalKey        = FindLocalKey();
            StateCodeExists = StateCache.IsValidStateCode(StateCode);
            if (StateCodeExists)
            {
                StateCodeIsNonState = false;
                if (IsNullOrWhiteSpace(CountyCode))
                {
                    AdminPageLevel = AdminPageLevel.State;
                    CodesAreValid  = true;
                }
                else // we have a CountyCode
                {
                    AdminPageLevel   = AdminPageLevel.County;
                    CountyCodeExists = Counties.StateCodeCountyCodeExists(StateCode,
                                                                          CountyCode);
                    if (CountyCodeExists)
                    {
                        if (IsNullOrWhiteSpace(LocalKey))
                        {
                            CodesAreValid = true;
                        }
                        else
                        {
                            AdminPageLevel = AdminPageLevel.Local;
                            LocalKeyExists = LocalDistricts.StateCodeLocalKeyExists(StateCode, LocalKey);
                            CodesAreValid  = LocalKeyExists;
                        }
                    }
                }
            }
            else
            {
                var nonStateCodesAllowed          = NonStateCodesAllowed;
                var nonStateCodesRequireSuperUser = NonStateCodesRequireSuperUser;
                if (nonStateCodesAllowed != null &&
                    nonStateCodesAllowed.Contains(StateCode) &&
                    (IsSuperUser || nonStateCodesRequireSuperUser == null ||
                     !nonStateCodesRequireSuperUser.Contains(StateCode)))
                {
                    StateCodeExists = true;
                    CodesAreValid   = true;
                    switch (StateCode)
                    {
                    case "US":
                        AdminPageLevel = AdminPageLevel.President;
                        break;

                    case "PP":
                        AdminPageLevel = AdminPageLevel.PresidentTemplate;
                        break;

                    case "U1":
                    case "U2":
                    case "U3":
                    case "U4":
                        AdminPageLevel = AdminPageLevel.Federal;
                        break;

                    case "":
                    case "LL":
                        AdminPageLevel = AdminPageLevel.AllStates;
                        break;

                    default:
                        StateCodeExists = false;
                        CodesAreValid   = false;
                        break;
                    }
                }
            }
        }
Example #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Page.IncludeJs("~/js/jq/jquery.cookie.js");
            Title = Format(TitleTag, PublicMasterPage.SiteName);
            var email = GetQueryString("email");

            EmailFixedAddress.InnerText = email;

            string tigerCode;

            var address               = Request.Cookies["Address"]?.Value;
            var stateCode             = Request.Cookies["State"]?.Value;
            var county                = Request.Cookies["County"]?.Value;
            var countySupervisors     = Request.Cookies["CountySupervisors"]?.Value;
            var congressionalDistrict = Request.Cookies["Congress"]?.Value;
            var stateSenateDistrict   = Request.Cookies["StateSenate"]?.Value;
            var stateHouseDistrict    = Request.Cookies["StateHouse"]?.Value;
            var place                  = Request.Cookies["Place"]?.Value;
            var district               = Request.Cookies["District"]?.Value;
            var cityCouncil            = Request.Cookies["CityCouncil"]?.Value;
            var elementary             = Request.Cookies["Elementary"]?.Value;
            var secondary              = Request.Cookies["Secondary"]?.Value;
            var unified                = Request.Cookies["Unified"]?.Value;
            var schoolDistrictDistrict = Request.Cookies["SchoolDistrictDistrict"]?.Value;
            var components             = WebService.GetComponentsFromCookies();

            var(latitude, longitude) = WebService.GetGeoFromCookies();

            if (!StateCache.IsValidStateCode(stateCode) || IsNullOrWhiteSpace(email) ||
                IsNullOrWhiteSpace(congressionalDistrict) ||
                IsNullOrWhiteSpace(stateSenateDistrict) ||
                !Offices.IsValidStateHouseDistrict(stateHouseDistrict, stateCode) ||
                IsNullOrWhiteSpace(county) || components == null || latitude == null ||
                longitude == null)
            {
                SafeTransferToError404();
                //EmailFixedAddress.InnerText = Join("|", stateCode.SafeString(), email.SafeString(),
                //  congressionalDistrict.SafeString(), stateSenateDistrict.SafeString(),
                //  stateHouseDistrict.SafeString(), county.SafeString(),
                //  components == null ? "null" : "components",
                //  (latitude?.ToString()).SafeString(), (longitude?.ToString()).SafeString());
            }

            WebService.UpdateAddresses(email, "SBRL", Empty, Empty, components,
                                       stateCode, congressionalDistrict, stateSenateDistrict, stateHouseDistrict, county,
                                       district, place, elementary, secondary, unified, cityCouncil, countySupervisors,
                                       schoolDistrictDistrict, latitude, longitude);

            Control tr;

            if (!IsNullOrWhiteSpace(address))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "Address"
                }.AddTo(tr);
                new TableCell {
                    Text = HttpUtility.UrlDecode(address)
                }.AddTo(tr);
            }

            //tr = new TableRow().AddTo(DistrictsTable);
            //new TableCell { Text = "State" }.AddTo(tr);
            //new TableCell { Text = StateCache.GetStateName(stateCode) }.AddTo(tr);

            if (!IsNullOrWhiteSpace(county) && stateCode != "DC")
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "County"
                }.AddTo(tr);
                new TableCell {
                    Text = CountyCache.GetCountyName(stateCode, county)
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(countySupervisors))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = stateCode == "DC" ? "Advisory Neighborhood Commission" : "County Supervisors"
                }.AddTo(tr);
                new TableCell
                {
                    Text = CountySupervisors.GetNameByStateCodeCountySupervisorsCode(stateCode,
                                                                                     countySupervisors)
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(congressionalDistrict) && stateCode != "DC")
            {
                if ((tigerCode =
                         TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("CD", stateCode,
                                                                                   congressionalDistrict)) != null)
                {
                    congressionalDistrict = tigerCode;
                }
                if (congressionalDistrict != "00")
                {
                    tr = new TableRow().AddTo(DistrictsTable);
                    new TableCell {
                        Text = "Congressional District"
                    }.AddTo(tr);
                    new TableCell {
                        Text = congressionalDistrict.TrimStart('0')
                    }.AddTo(tr);
                }
            }

            if (!IsNullOrWhiteSpace(stateSenateDistrict))
            {
                if ((tigerCode =
                         TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SS", stateCode,
                                                                                   stateSenateDistrict)) != null)
                {
                    stateSenateDistrict = tigerCode;
                }
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = stateCode == "DC" ? "Ward" : "State Senate District"
                }.AddTo(tr);
                new TableCell {
                    Text = stateSenateDistrict?.TrimStart('0')
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(stateHouseDistrict))
            {
                if ((tigerCode =
                         TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SH", stateCode,
                                                                                   stateHouseDistrict)) != null)
                {
                    stateHouseDistrict = tigerCode;
                }
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "State House District"
                }.AddTo(tr);
                new TableCell {
                    Text = stateHouseDistrict.TrimStart('0')
                }.AddTo(tr);
            }

            if (stateCode != "DC")
            {
                var districts = new List <string>();
                if (!IsNullOrWhiteSpace(place))
                {
                    districts.Add(TigerPlaces.GetNameByStateCodeTigerCode(stateCode, place));
                }
                if (!IsNullOrWhiteSpace(district))
                {
                    districts.Add(TigerPlaces.GetNameByStateCodeTigerCode(stateCode, district));
                }
                if (districts.Count > 0)
                {
                    tr = new TableRow().AddTo(DistrictsTable);
                    new TableCell {
                        Text = "Local District"
                    }.AddTo(tr);
                    new TableCell {
                        Text = Join(", ", districts.Distinct())
                    }.AddTo(tr);
                }
            }

            if (!IsNullOrWhiteSpace(cityCouncil) && stateCode != "DC")
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "City Council"
                }.AddTo(tr);
                new TableCell
                {
                    Text = CityCouncil.GetNameByStateCodeCityCouncilCode(stateCode, cityCouncil)
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(elementary))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "Elementary School District"
                }.AddTo(tr);
                new TableCell
                {
                    Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, elementary,
                                                                             "E")
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(secondary))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "Secondary School District"
                }.AddTo(tr);
                new TableCell
                {
                    Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, secondary,
                                                                             "S")
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(unified))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "Unified School District"
                }.AddTo(tr);
                new TableCell
                {
                    Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, unified, "U")
                }.AddTo(tr);
            }

            if (!IsNullOrWhiteSpace(schoolDistrictDistrict))
            {
                tr = new TableRow().AddTo(DistrictsTable);
                new TableCell {
                    Text = "School Voting District"
                }.AddTo(tr);
                new TableCell
                {
                    Text = SchoolDistrictDistricts.GetNameByStateCodeSchoolDistrictDistrictCode(
                        stateCode, schoolDistrictDistrict)
                }.AddTo(tr);
            }
        }
Example #20
0
 private static bool IsDataCodeValidStateCode(string dataCode)
 {
     return(StateCache.IsValidStateCode(dataCode));
 }