Exemplo n.º 1
0
        public IPostResponse PlaceVote([FromContent] Vote vote)
        {
            _logger.Trace($"Request to register {vote.GetLogString()}");
            var serverVote = new ServerRecordedVote()
            {
                ClientId                   = vote.Id,
                BallotId                   = vote.BallotId,
                MachineIPAddress           = vote.MachineIPAddress,
                MachineId                  = vote.MachineId,
                MachineName                = vote.MachineName,
                RecordedTime               = vote.RecordedTime,
                ServerRegsiteredMachinedId = vote.ServerRegsiteredMachinedId,
                VoteOption                 = vote.VoteOption,
                ServerRecordedTime         = DateTime.Now
            };

            var success = VoteRepository.Save(serverVote);

            if (success)
            {
                _logger.Trace($"Vote recorded with vote ID {serverVote.Id}");
            }


            return(success ?
                   new PostResponse(PostResponse.ResponseStatus.Created, "", new { ID = serverVote.Id, SetLock = true })
                                : new PostResponse(PostResponse.ResponseStatus.Conflict, "", new { ID = -1, Error = "Unable to save vote, please try again" }));
        }