public Election FindElectionForUser(Guid electionId, User user)
{
Election election;
if (!electionsDict.TryGetValue(electionId, out election))
{
return(null);
}
TryDecryptElectionResultIfFinished(election);
if (election.Candidates.Any(info => info.Id == user.Id))
{
lock (election)
{
election = election.Clone();
}
var candidate = election.Candidates.FirstOrDefault(info => info.Id == user.Id);
if (candidate != null)
{
candidate.IsMe = true;
}
PrivateKey privateKey;
if (electionPrivateKeys.TryGetValue(election.Id, out privateKey))
{
election.PrivateKeyForCandidates = privateKey;
}
var winner = election.FindWinner();
if (winner != null && winner.Id == user.Id)
{
election.Candidates.ForEach(info =>
{
var u = authController.FindUserAuthorized(info.Name);
if (u != null)
{
info.PrivateNotesForWinner = u.PrivateNotes;
}
}
);
}
}
return(election);
}