/// <summary> /// Update Candidate's Votes information. /// </summary> /// <param name="candidatePublicKey"></param> /// <param name="amount"></param> private long UpdateCandidateInformation(string candidatePublicKey, long amount) { var candidateVotes = State.CandidateVotes[candidatePublicKey]; if (candidateVotes == null) { candidateVotes = new CandidateVote { Pubkey = candidatePublicKey.ToByteString(), ObtainedActiveVotingRecordIds = { Context.TransactionId }, ObtainedActiveVotedVotesAmount = amount, AllObtainedVotedVotesAmount = amount }; } else { candidateVotes.ObtainedActiveVotingRecordIds.Add(Context.TransactionId); candidateVotes.ObtainedActiveVotedVotesAmount = candidateVotes.ObtainedActiveVotedVotesAmount.Add(amount); candidateVotes.AllObtainedVotedVotesAmount = candidateVotes.AllObtainedVotedVotesAmount.Add(amount); } State.CandidateVotes[candidatePublicKey] = candidateVotes; return(candidateVotes.ObtainedActiveVotedVotesAmount); }
public async Task <ActionResult <CandidateVote> > PostCandidateVote(CandidateVote candidateVote) { _context.CandidateVote.Add(candidateVote); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCandidateVote", new { id = candidateVote.Id }, candidateVote)); }
/// <summary> /// Update Candidate's Votes information. /// </summary> /// <param name="candidatePublicKey"></param> /// <param name="amount"></param> /// <param name="voteId"></param> private long UpdateCandidateInformation(string candidatePublicKey, long amount, Hash voteId) { var candidateVotes = State.CandidateVotes[candidatePublicKey]; if (candidateVotes == null) { candidateVotes = new CandidateVote { Pubkey = ByteStringHelper.FromHexString(candidatePublicKey), ObtainedActiveVotingRecordIds = { voteId }, ObtainedActiveVotedVotesAmount = amount, AllObtainedVotedVotesAmount = amount }; } else { candidateVotes.ObtainedActiveVotingRecordIds.Add(voteId); candidateVotes.ObtainedActiveVotedVotesAmount = candidateVotes.ObtainedActiveVotedVotesAmount.Add(amount); candidateVotes.AllObtainedVotedVotesAmount = candidateVotes.AllObtainedVotedVotesAmount.Add(amount); } State.CandidateVotes[candidatePublicKey] = candidateVotes; return(candidateVotes.ObtainedActiveVotedVotesAmount); }
public async Task <IActionResult> PutCandidateVote(int id, CandidateVote candidateVote) { if (id != candidateVote.Id) { return(BadRequest()); } _context.Entry(candidateVote).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CandidateVoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }