public bool VoteForCandidate(string login, string gameRefID, string characterID, string candidateCharacterID) { if (!electionInfo.started) { log.InfoFormat("VoteForCandidate error: voting not started"); return(false); } if (ExistElector(characterID)) { log.InfoFormat("VoteForCandidate error: you already make election"); return(false); } var player = application.Players.GetExistingPlayer(gameRefID); if (player == null || player.Data == null) { log.InfoFormat("VoteForCandidate error: player not found"); return(false); } var character = player.Data.GetCharacter(characterID); if (character == null) { log.InfoFormat("VoteForCandidate error: character not found"); return(false); } var candidate = GetCandidate(candidateCharacterID); if (candidate == null) { log.InfoFormat("VoteForCandidate error: candidate not found"); return(false); } if (character.Race != candidate.race) { log.InfoFormat("VoteForCandidate error: candidate invalid race"); return(false); } candidate.IncrementVoices(); application.DB.CommanderCandidates.Save(candidate); CommanderElector elector = new CommanderElector { characterID = characterID, gameRefID = gameRefID, candidateCharacterID = candidateCharacterID, login = login, race = character.Race }; application.DB.CommanderElectors.Save(elector); log.Info("you successfully vote"); return(true); }
public bool ExistElector(string characterID) { CommanderElector elector = application.DB.CommanderElectors.FindOne(Query <CommanderElector> .EQ(ce => ce.characterID, characterID)); return(elector != null); }