Exemplo n.º 1
0
        //private IEnumerable<ElectionsFutureRow> GetFutureElections(string stateCode)
        //{
        //  var key = stateCode + "|ElectionsFutureByState";
        //  var data = GetDataCache(key);
        //  if (data == null)
        //  {
        //    data = ElectionsFuture.GetIdData(stateCode, string.Empty, string.Empty);
        //    PutDataCache(key, data);
        //  }
        //  return data as ElectionsFutureTable;
        //}

        private string GetLocalizedOfficeName(string officeKey)
        {
            var officeTitle = string.Empty;

            if (!Offices.IsStateOrFederalOffice(officeKey))
            {
                if (Offices.IsCountyOffice(officeKey))
                {
                    officeTitle +=
                        CountyCache.GetCountyName(Offices.GetStateCodeFromKey(officeKey),
                                                  Offices.GetCountyCodeFromKey(officeKey));
                }
                else
                {
                    officeTitle += VotePage.GetPageCache()
                                   .LocalDistricts.GetLocalDistrict(
                        Offices.GetStateCodeFromKey(officeKey),
                        Offices.GetCountyCodeFromKey(officeKey),
                        Offices.GetLocalCodeFromKey(officeKey));
                }
                officeTitle += " ";
            }

            officeTitle +=
                Offices.FormatOfficeName(PageCache.Offices.GetOfficeLine1(officeKey),
                                         PageCache.Offices.GetOfficeLine2(officeKey), officeKey);

            return(officeTitle);
        }
Exemplo n.º 2
0
        private void AnalyzeElectoralClass()
        {
            string titleContentDescription;
            var    metaContentLocation = Empty;

            switch (_ElectoralClass)
            {
            case ElectoralClass.USPresident:
                titleContentDescription = "Current US President and Vice President";
                break;

            case ElectoralClass.USSenate:
                titleContentDescription = "Current US Senators";
                break;

            case ElectoralClass.USHouse:
                titleContentDescription = "Current US House Members";
                break;

            case ElectoralClass.USGovernors:
                titleContentDescription = "Current State Governors and Lieutenant Governors";
                break;

            case ElectoralClass.State:
                titleContentDescription =
                    $"Current {StateCache.GetStateName(_StateCode)} Elected Representatives";
                break;

            case ElectoralClass.County:
                titleContentDescription = "Current County Representatives";
                metaContentLocation     =
                    $"{CountyCache.GetCountyName(_StateCode, _CountyCode)}, {StateCache.GetStateName(_StateCode)}";
                break;

            case ElectoralClass.Local:
                titleContentDescription = "Current Local District Representatives";
                metaContentLocation     =
                    $"{LocalDistricts.GetName(_StateCode, _LocalKey)}," +
                    $" {CountyCache.GetCountyName(_StateCode, _CountyCode)}, {StateCache.GetStateName(_StateCode)}";
                break;

            default:
                titleContentDescription = "Elected Representatives";
                break;
            }

            var metaContentDescription = titleContentDescription;

            if (metaContentLocation != Empty)
            {
                metaContentDescription += $", {metaContentLocation}";
            }

            //PageHeading.MainHeadingText = titleContentDescription;
            H1.InnerText    = titleContentDescription;
            Title           = Format(TitleTag, metaContentDescription, PublicMasterPage.SiteName);
            MetaDescription = Format(MetaDescriptionTag, metaContentDescription);
        }
Exemplo n.º 3
0
        public static string FindCountyCode()
        {
            // reworked to eliminate ViewState references
            var stateCode = FindStateCode();

            if (IsNullOrWhiteSpace(stateCode))
            {
                return(Empty);
            }

            var countyCode = QueryCounty;

            if (IsNullOrWhiteSpace(countyCode))
            {
                if (IsMasterUser || IsAdminUser)
                {
                    countyCode = UserCountyCode;
                    if (IsNullOrWhiteSpace(countyCode))
                    {
                        var localKey = FindLocalKey();
                        if (!IsNullOrEmpty(localKey))
                        {
                            // if there is a local key and there is no county in the query string,
                            // we must look up a county. If there's more than 1, we just use the first we find.
                            var counties = LocalIdsCodes.FindCounties(stateCode, localKey);
                            countyCode = counties.Length == 0 ? Empty : counties[0];
                        }
                        else
                        {
                            countyCode = Elections.GetCountyCodeFromKey(QueryElection);
                            if (IsNullOrWhiteSpace(countyCode))
                            {
                                countyCode = Offices.GetCountyCodeFromKey(QueryOffice);
                            }
                        }
                    }
                }
            }
            return(!IsNullOrWhiteSpace(countyCode) &&
                   CountyCache.CountyExists(stateCode, countyCode)
        ? countyCode
        : Empty);
        }
        private void FillInCountyLinks()
        {
            var countyKeys =
                Elections.GetCountyElectionKeysFromKey(_ElectionKey)
                .Select(
                    k =>
                    new
            {
                key  = k,
                name =
                    CountyCache.GetCountyName(_StateCode, Elections.GetCountyCodeFromKey(k))
            })
                .OrderBy(k => k.name, StringComparer.OrdinalIgnoreCase);

            foreach (var key in countyKeys)
            {
                new HtmlAnchor
                {
                    InnerText = $"Go to {key.name} Election",
                    HRef      = AppendOpenAll(UrlManager.GetElectionPageUri(key.key).ToString())
                }
            }
Exemplo n.º 5
0
        public static string FormatLegislativeDistrictsFromQueryString(
            string separator = "<br />")
        {
            var lines = new List <string>();

            if (QueryState != "DC")
            {
                if (QueryCongress != "000")
                {
                    lines.Add("US House District " + QueryCongress.TrimStart('0') + " " +
                              StateCache.GetStateName(QueryState));
                }
                if (QueryStateSenate != "000")
                {
                    lines.Add(StateCache.GetStateName(QueryState) + " Senate District " +
                              QueryStateSenate.TrimStart('0'));
                }
                if (QueryStateHouse != "000")
                {
                    lines.Add(StateCache.GetStateName(QueryState) + " House District " +
                              QueryStateHouse.TrimStart('0'));
                }
                if (QueryCounty != string.Empty)
                {
                    lines.Add(CountyCache.GetCountyName(QueryState, QueryCounty));
                }
            }
            else if (QueryStateSenate != "000")
            {
                lines.Add("Ward " + QueryStateSenate.TrimStart('0'));
            }

            if (separator == null)
            {
                return("<span>" + string.Join("</span><span>", lines) + "</span>");
            }
            return(string.Join(separator, lines));
        }
        private void FillInDropdowns(string electionKey, string countyCode,
                                     string congress, string stateSenate, string stateHouse)
        {
            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            StateCache.Populate(StateList, "<select a state>", string.Empty, stateCode);
            CountyCache.Populate(CountyList, stateCode, "<select a county>", string.Empty,
                                 countyCode);
            // reduce CongressionalDistrict codes from 3 to 2 characters
            if (congress.Length == 3)
            {
                congress = congress.Substring(1);
            }
            Utility.PopulateFromList(CongressList,
                                     new List <SimpleListItem> {
                new SimpleListItem(string.Empty, "<select a congressional district>")
            }
                                     .Union(Offices.GetDistrictItems(stateCode, OfficeClass.USHouse)
                                            .Select(i =>
            {
                i.Value = i.Value.Substring(1);
                return(i);
            })), congress);
            Utility.PopulateFromList(StateSenateList,
                                     new List <SimpleListItem> {
                new SimpleListItem(string.Empty, "<select a state senate district>")
            }
                                     .Union(Offices.GetDistrictItems(stateCode, OfficeClass.StateSenate)), stateSenate);
            Utility.PopulateFromList(StateHouseList,
                                     new List <SimpleListItem> {
                new SimpleListItem(string.Empty, "<select a state house district>")
            }
                                     .Union(Offices.GetDistrictItems(stateCode, OfficeClass.StateHouse)), stateHouse);
            Utility.PopulateFromList(ElectionList,
                                     BulkEmailPage.GetPreviewElectionItems(stateCode, string.Empty, string.Empty,
                                                                           "<select an election>"),
                                     electionKey);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public static string County_Code()
        {
            var viewStateCountyCode = SecurePage.GetViewStateCountyCode();

            if (viewStateCountyCode != null)
            {
                return(viewStateCountyCode);
            }

            var countyCode = string.Empty;

            if (
                !VotePage.IsSessionStateEnabled ||
                !SecurePage.IsSignedIn
                )
            //if (db.Is_User_Anonymous())
            {
                if (!string.IsNullOrEmpty(VotePage.QueryElection))
                {
                    //could be old ElectionKey format
                    countyCode = Elections.GetCountyCodeFromKey(
                        //db.ElectionKey_New_Format(db.QueryString("Election")));
                        VotePage.QueryElection);
                }
                else if (!string.IsNullOrEmpty(VotePage.QueryOffice))
                {
                    countyCode = Offices.GetCountyCodeFromKey(VotePage.QueryOffice);
                }
                else if (!string.IsNullOrEmpty(VotePage.QueryCounty))
                {
                    countyCode = VotePage.QueryCounty;
                }
                if (
                    (countyCode == "000") || //Directory of Counties
                    (CountyCache.CountyExists(State_Code()
                                              , countyCode))
                    )
                {
                    return(countyCode);
                }
                return(string.Empty);
            }

            //only MASTER or State ADMIN can change CountyCode of county
            //Setting UserLocalCode empty resets to County level security

            if ((SecurePage.IsMasterUser || (SecurePage.IsStateAdminUser)) &&
                !string.IsNullOrEmpty(VotePage.QueryCounty)
                )
            {
                Session_Put("UserCountyCode", VotePage.QueryCounty);
                Session_Put("UserLocalCode", string.Empty);
            }
            else
            {
                //Need to reset CountyCode to empty
                //When there is a StateCode query string
                //but no CountyCode query string
                if (!string.IsNullOrEmpty(State_Code()))
                {
                    Session_Put("UserCountyCode", string.Empty);
                    Session_Put("UserLocalCode", string.Empty);
                }
            }

            if (CountyCache.CountyExists(
                    State_Code()
                    , User_CountyCode()))
            {
                return(User_CountyCode());
            }
            return(string.Empty);
        }
Exemplo n.º 9
0
        public static string FormatLegislativeDistrictsFromQueryString(
            string separator = "<br />")
        {
            var lines = new List <string>();

            if (QueryState != "DC")
            {
                string county = null;
                if (!IsNullOrWhiteSpace(QueryCounty))
                {
                    lines.Add(county = CountyCache.GetCountyName(QueryState, QueryCounty));
                }

                if (!IsNullOrWhiteSpace(QueryCountySupervisors))
                {
                    lines.Add(CountySupervisors.GetNameByStateCodeCountySupervisorsCode(QueryState,
                                                                                        QueryCountySupervisors));
                }

                string tigerCode;
                if (QueryCongress != "000")
                {
                    var congressionalDistrict = QueryCongress;
                    if (congressionalDistrict.Length == 3)
                    {
                        congressionalDistrict = congressionalDistrict.Substring(1);
                    }
                    if ((tigerCode =
                             TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("CD", QueryState,
                                                                                       congressionalDistrict)) != null)
                    {
                        congressionalDistrict = tigerCode;
                    }
                    if (congressionalDistrict != "00")
                    {
                        lines.Add("US House District " + congressionalDistrict.TrimStart('0') + " " +
                                  StateCache.GetStateName(QueryState));
                    }
                }

                if (QueryStateSenate != "000")
                {
                    var stateSenateDistrict = QueryStateSenate;
                    if ((tigerCode =
                             TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SS", QueryState,
                                                                                       stateSenateDistrict)) != null)
                    {
                        stateSenateDistrict = tigerCode;
                    }
                    lines.Add(StateCache.GetStateName(QueryState) + " Senate District " +
                              stateSenateDistrict.TrimStart('0'));
                }

                if (!IsNullOrWhiteSpace(QueryStateHouse))
                {
                    var stateHouseDistrict = QueryStateHouse;
                    if ((tigerCode =
                             TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SH", QueryState,
                                                                                       stateHouseDistrict)) != null)
                    {
                        stateHouseDistrict = tigerCode;
                    }
                    lines.Add(StateCache.GetStateName(QueryState) + " House District " +
                              stateHouseDistrict.TrimStart('0'));
                }

                string district   = null;
                string lastResort = null;
                if (QueryDistrict != Empty)
                {
                    district = TigerPlaces.GetLongNameByStateCodeTigerCode(QueryState, QueryDistrict);
                    if (!IsNullOrWhiteSpace(district) && district.IsNeIgnoreCase(county))
                    {
                        if (district.EndsWith(" CCD") || district.EndsWith(" CDP"))
                        {
                            lastResort = district.Substring(0, district.Length - 4);
                        }
                        else
                        {
                            lines.Add(district);
                        }
                    }
                }

                if (QueryPlace != Empty)
                {
                    var place = TigerPlaces.GetLongNameByStateCodeTigerCode(QueryState, QueryPlace);
                    if (!IsNullOrWhiteSpace(place) && place.IsNeIgnoreCase(district) &&
                        place.IsNeIgnoreCase(county))
                    {
                        if (place.EndsWith(" CCD") || place.EndsWith(" CDP"))
                        {
                            lastResort = place.Substring(0, place.Length - 4);
                        }
                        else
                        {
                            lines.Add(place);
                            lastResort = null;
                        }
                    }
                }
                if (lastResort != null &&
                    (county == null ||
                     !county.StartsWith(lastResort, StringComparison.OrdinalIgnoreCase)))
                {
                    lines.Add(lastResort);
                }

                if (!IsNullOrWhiteSpace(QueryCityCouncil))
                {
                    lines.Add(
                        CityCouncil.GetNameByStateCodeCityCouncilCode(QueryState, QueryCityCouncil));
                }
            }
            else if (QueryStateSenate != "000")
            {
                if (!IsNullOrWhiteSpace(QueryStateSenate))
                {
                    lines.Add("Ward " + QueryStateSenate.TrimStart('0'));
                }
                if (!IsNullOrWhiteSpace(QueryCountySupervisors))
                {
                    lines.Add(
                        CountySupervisors.GetNameByStateCodeCountySupervisorsCode(QueryState,
                                                                                  QueryCountySupervisors));
                }
            }

            if (!IsNullOrWhiteSpace(QueryElementary))
            {
                lines.Add(
                    TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QueryElementary,
                                                                      "E"));
            }

            if (!IsNullOrWhiteSpace(QuerySecondary))
            {
                lines.Add(
                    TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QuerySecondary,
                                                                      "S"));
            }

            if (!IsNullOrWhiteSpace(QueryUnified))
            {
                lines.Add(
                    TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QueryUnified, "U"));
            }

            if (!IsNullOrWhiteSpace(QuerySchoolDistrictDistrict))
            {
                lines.Add(
                    SchoolDistrictDistricts.GetNameByStateCodeSchoolDistrictDistrictCode(
                        QueryState, QuerySchoolDistrictDistrict));
            }

            if (separator == null)
            {
                return("<span>" + Join("</span><span>", lines) + "</span>");
            }
            return(Join(separator, lines));
        }