예제 #1
0
        /// <summary>
        /// Register Vote
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public async Task RegisterVote(VoteRequestViewModel record)
        {
            Campaign campaign = await campaignRepository.Retrieve(record.CompanyId, record.CampaignId);

            if (campaign == null)
            {
                throw new NotFoundException();
            }

            VoteViewModel vote = new VoteViewModel();

            vote.CampaignId       = record.CampaignId;
            vote.CompanyId        = record.CompanyId;
            vote.CampaignOptionId = record.CampaignOptionId;

            if (campaign.Auth)
            {
                string identity = Encryptor.Encrypt(string.Join(Environment.NewLine, record.VoterIdentity));

                if (await HasAlreadyVoted(vote.CampaignId, identity))
                {
                    throw new NonUniqueRecordException();
                }

                vote.VoterIdentity = identity;
            }

            await voteRepository.RegisterVote(Mapper.Map <Vote>(vote));
        }
예제 #2
0
        public async Task <ActionResult <VoteResponseViewModel> > Post(VoteRequestViewModel input)
        {
            var userId = this.userManager.GetUserId(this.User);

            await this.votesService.VoteAsync(input.PostId, userId, input.IsUpVote);

            var votes = this.votesService.GetVotesCount(input.PostId);

            return(new VoteResponseViewModel {
                VotesCount = votes
            });
        }
예제 #3
0
 public async Task RegisterVote([FromBody] VoteRequestViewModel model)
 {
     await voteService.RegisterVote(model);
 }