Exemplo n.º 1
0
        public async Task <IActionResult> Vote([FromBody] VoteCandidate vote, [FromServices] VoteContext voteContext)
        {
            var votingId = await ValidateGuidVoting(vote.VortingGuid);

            if (votingId > 0)
            {
                try
                {
                    var voteCandidate = new VotesCandidate
                    {
                        CandidateId = vote.CandidateId,
                        VotingId    = votingId
                    };

                    await voteContext.VotesCandidates.AddAsync(voteCandidate);

                    await voteContext.SaveChangesAsync();

                    await CountCandidatesVotes(vote.VortingGuid, votingId);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(Ok(vote));
        }
Exemplo n.º 2
0
 public VoteCandidateController(ICacheOperation cacheOperation) //: base(toafcContextOptions, cacheOperation)
 {
     voteCandidate = new VoteCandidate(cacheOperation);
 }