Ejemplo n.º 1
0
 public void GetData(string electionKey, string congress, string stateSenate,
                     string stateHouse, string countyCode)
 {
     ElectionKey = electionKey;
     DataTable   = ElectionsPoliticians.GetSampleBallotData(electionKey, congress,
                                                            stateSenate, stateHouse, countyCode);
 }
Ejemplo n.º 2
0
            //public void GetData(string electionKey, string congress, string stateSenate,
            //  string stateHouse, string countyCode)
            //{
            //  _StateCode = Elections.GetStateCodeFromKey(electionKey);
            //  ElectionKey = electionKey;
            //  DataTable = ElectionsPoliticians.GetSampleBallotData(electionKey, congress,
            //    stateSenate, stateHouse, countyCode);
            //}

            public void GetData(string electionKey, string congress, string stateSenate,
                                string stateHouse, string countyCode, string district, string place, string elementary,
                                string secondary, string unified, string cityCouncil, string countySupervisors,
                                string schoolDistrictDistrict)
            {
                //_StateCode = Elections.GetStateCodeFromKey(electionKey);
                ElectionKey = electionKey;
                DataTable   = ElectionsPoliticians.GetSampleBallotData(electionKey, congress, stateSenate,
                                                                       stateHouse, countyCode, district, place, elementary, secondary, unified, cityCouncil,
                                                                       countySupervisors, schoolDistrictDistrict);
            }
Ejemplo n.º 3
0
 public void GetData(string electionKey, string congress, string stateSenate, string stateHouse, string countyCode, bool includeOptionalData)
 {
     DataTable = ElectionsPoliticians.GetSampleBallotData(electionKey, congress,
                                                          stateSenate, stateHouse, countyCode, includeOptionalData);
 }
Ejemplo n.º 4
0
        public void voterInfoQuery(double latitude, double longitude,
                                   string electionDay, string state, string accessKey)
        {
            var result = new VoterBallotIdentifiersRetrieveData
            {
                status = "OK", success = true, latitude = latitude, longitude = longitude, kind = "voteusa#voterInfoQuery"
            };

            state = state.ToUpperInvariant();
            if (StateCache.IsValidStateCode(state))
            {
                result.state = state;
            }
            else
            {
                result.status  = "Invalid state";
                result.success = false;
            }

            if (DateTime.TryParseExact(electionDay, "yyyy-MM-dd", new CultureInfo("en-US"),
                                       DateTimeStyles.None, out var electionDate))
            {
                result.electionDay = electionDay;
            }
            else
            {
                result.status  = "Invalid electionDay";
                result.success = false;
            }

            if (accessKey != "M@gicWord")
            {
                result.status  = "Unauthorized";
                result.success = false;
            }

            // There could be multiple election keys if it's a primary day
            var keys = Elections.GetStateElectionKeysForDate(state, electionDate);

            if (keys.Count < 1)
            {
                result.status  = $"No elections found for {electionDay} in {state}";
                result.success = false;
            }

            if (result.success) // all validation passed
            {
                var tiger = TigerLookup.LookupAll(latitude, longitude);
                // handle the keys -- first one is arbitrarily the main election
                result.election = new ElectionInfo
                {
                    electionDay = electionDay,
                    name        = Elections.GetElectionDesc(keys[0]),
                    id          = keys[0]
                };
                // if there are additional elections, post them
                result.otherElections = new List <ElectionInfo>();
                foreach (var key in keys.Skip(1))
                {
                    result.otherElections.Add(new ElectionInfo
                    {
                        electionDay = electionDay,
                        name        = Elections.GetElectionDesc(key),
                        id          = key
                    });
                }
                result.contests = new List <Contest>();
                foreach (var key in keys)
                {
                    var data = ElectionsPoliticians.GetSampleBallotData(key, tiger.Congress,
                                                                        tiger.Upper, tiger.Lower, tiger.County, tiger.District, tiger.Place,
                                                                        tiger.Elementary, tiger.Secondary, tiger.Unified, tiger.CityCouncil,
                                                                        tiger.CountySupervisors, Empty);
                    var contests = data.Rows.OfType <DataRow>().GroupBy(r =>
                                                                        new { ElectionKey = r.ElectionKey(), OfficeKey = r.OfficeKey() }).ToList();
                    foreach (var contest in contests)
                    {
                        var candidates = new List <Candidate>();
                        foreach (var candidate in contest)
                        {
                            candidates.Add(new Candidate
                            {
                                id   = candidate.PoliticianKey(),
                                name = Politicians.FormatName(candidate)
                            });
                        }
                        result.contests.Add(new Contest
                        {
                            office     = Offices.FormatOfficeName(contest.First()),
                            id         = $"{contest.Key.ElectionKey}|{contest.Key.OfficeKey}",
                            candidates = candidates
                        });
                    }
                }
            }

            var javaScriptSerializer = new JavaScriptSerializer();
            var jsonString           = javaScriptSerializer.Serialize(result);

            Context.Response.Write(jsonString);
        }