Beispiel #1
0
        private void UpdateCountyCandidates(JsonCandidateModel jsonLocality, County county, Ballot ballot, List <Party> parties)
        {
            var newResults = jsonLocality.Votes.Select(r => CreateCandidateResult(r, ballot, parties, null, county.CountyId, ElectionDivision.County))
                             .ToList();
            var turnout = GetTurnout(jsonLocality.Fields);

            turnout.Division = ElectionDivision.County;
            turnout.BallotId = ballot.BallotId;
            turnout.CountyId = county.CountyId;
            _turnouts.Add(turnout);
            _candidates.AddRange(newResults);
        }
Beispiel #2
0
        private static async Task <Locality> UpdateSirutaForLocality(
            JsonCandidateModel jsonLocality,
            ApplicationDbContext dbContext, int countyId)
        {
            Locality locality;

            locality = new Locality
            {
                Name     = jsonLocality.uat_name,
                CountyId = countyId,
                Siruta   = jsonLocality.uat_siruta.GetValueOrDefault()
            };
            dbContext.Localities.Update(locality);
            await dbContext.SaveChangesAsync();

            return(locality);
        }
Beispiel #3
0
        private async Task UpdateLocalityCandidates(List <Locality> localities, JsonCandidateModel jsonLocality,
                                                    ApplicationDbContext dbContext, County county, Ballot ballot, List <Party> parties)
        {
            var locality =
                localities.FirstOrDefault(l => l.Siruta == jsonLocality.uat_siruta);

            if (locality == null)
            {
                Console.WriteLine($"Siruta not found for {jsonLocality.uat_name} - {jsonLocality.uat_siruta}");
                locality = await UpdateSirutaForLocality(jsonLocality, dbContext, county.CountyId);
            }
            var turnout = GetTurnout(jsonLocality.Fields);

            turnout.Division   = ElectionDivision.Locality;
            turnout.BallotId   = ballot.BallotId;
            turnout.LocalityId = locality.LocalityId;
            turnout.CountyId   = county.CountyId;
            _turnouts.Add(turnout);
            var newResults = jsonLocality.Votes.Select(r => CreateCandidateResult(r, ballot, parties, locality.LocalityId, locality.CountyId))
                             .ToList();

            _candidates.AddRange(newResults);
        }