Пример #1
0
        public async Task <JsonResult> SubmitVoteForPlace(Guid eventId, Guid optionId, Guid usersVoteId, WillAttend?willAttend)
        {
            var userId    = User.Identity.GetUserId();
            var voteModel = new VoteForPlace()
            {
                Id         = usersVoteId,
                PlaceId    = optionId,
                UserId     = userId,
                WillAttend = willAttend
            };

            await _votingService.SubmitVoteForPlace(voteModel);

            var votes = await _votingService.GetVotesForPlaceAsync(eventId, optionId);

            var totalNumberOfVoters = await _votingService.GetTotalNumberOfVotersForEvent(eventId);

            return(Json(new
            {
                Option = new OptionViewModel()
                {
                    UsersVote = MappingHelper.MapToUsersVoteModel(votes, userId),
                    Votes = MappingHelper.MapToVotesViewModel(votes)
                },
                TotalNumberOfVoters = totalNumberOfVoters
            },
                        JsonRequestBehavior.AllowGet));
        }