public Guid StartElection(string electionName, User firstCandidate, bool isPublic, DateTime nominateTill, DateTime till)
{
var homoKeyPair = HomoKeyPair.GenKeyPair(MaxVotesPerElection);
var election = new Election
{
Id = Guid.NewGuid(),
Name = electionName,
NominateTill = nominateTill,
VoteTill = till,
PublicKey = homoKeyPair.PublicKey,
Votes = new List <Vote>(),
Candidates = new List <CandidateInfo> {
CandidateInfo.Create(firstCandidate)
},
IsPublic = isPublic
};
statePersister.SaveKey(election.Id, homoKeyPair.PrivateKey);
lock (electionsList)
{
electionPrivateKeys[election.Id] = homoKeyPair.PrivateKey;
electionsDict[election.Id] = election;
electionsList.AddFirst(election);
while (electionsList.Count > MaxElections)
{
var node = electionsList.Last;
Election dummy;
electionsDict.TryRemove(node.Value.Id, out dummy);
electionsList.RemoveLast();
}
}
return(election.Id);
}