public static bool AllowsDivision(this Ballot ballot, ElectionDivision division, int localityId) { if (ballot.BallotType == BallotType.Mayor && division == ElectionDivision.County && localityId.IsCapitalCity()) { return(true); } return(BallotSettings.BallotTypeMatchList[ballot.BallotType].Any(t => t == division)); }
private async Task <List <Winner> > GetWinners(int ballotId, int?countyId, ElectionDivision division) { var query = CreateWinnersQuery() .Where(w => w.BallotId == ballotId && w.Division == division && w.CountyId == countyId).ToListAsync(); var winnersKey = MemoryCache.CreateWinnersKey(ballotId, countyId, division); var winners = await _appCache.GetOrAddAsync(winnersKey, () => query, DateTimeOffset.Now.AddMinutes(10)); return(winners); }
private static CandidateResult CreateCandidateResult(Vote vote, Ballot ballot, List <Party> parties, int?localityId, int?countyId, ElectionDivision division = ElectionDivision.Locality) { var candidateResult = new CandidateResult { BallotId = ballot.BallotId, Division = division, Votes = vote.Votes, Name = vote.Candidate, CountyId = countyId, LocalityId = localityId, Seats1 = vote.Mandates1, Seats2 = vote.Mandates2 }; var partyName = ballot.BallotType == BallotType.LocalCouncil || ballot.BallotType == BallotType.CountyCouncil ? vote.Candidate : vote.Party; if (partyName.IsNotEmpty()) { candidateResult.PartyId = parties.FirstOrDefault(p => p.Alias.ContainsString(partyName))?.Id ?? parties.FirstOrDefault(p => p.Name.ContainsString(partyName))?.Id; } candidateResult.PartyName = partyName; if (candidateResult.PartyId == null && partyName.IsNotEmpty()) { candidateResult.ShortName = partyName.GetPartyShortName(null); } return(candidateResult); }
public static string CreateWinnersKey(int ballotId, int?countyId, ElectionDivision division) { return($"winner-{ballotId}-{countyId}-{division}"); }
private static Winner CreateWinner(int ballotId, int?countyId, CandidateResult localityWinner, Turnout turnoutForLocality, ElectionDivision division) { var winner = new Winner { BallotId = ballotId, CandidateId = localityWinner.Id, CountyId = countyId, Division = division, Name = localityWinner.Name, PartyId = localityWinner.PartyId, TurnoutId = turnoutForLocality?.Id, }; return(winner); }
private static Winner CreateWinner(Ballot ballot, CandidateResult countyWinner, ElectionMapWinner electionMapWinner, int turnoutId, int countryId, ElectionDivision division) { return(new Winner { BallotId = ballot.BallotId, Ballot = ballot, CandidateId = countyWinner.Id, Name = electionMapWinner.Winner.Name, PartyId = electionMapWinner.Winner.Party?.Id, Votes = electionMapWinner.Winner.Votes, TurnoutId = turnoutId, CountryId = countryId, Division = division }); }