コード例 #1
0
ファイル: VoteAppService.cs プロジェクト: igorbmaciel/Poll
        public async Task <AddVoteResponse> AddVote(AddVoteCommand command)
        {
            var response = await _mediator.Send(command);

            if (Notification.HasNotification())
            {
                return(null);
            }

            return(response);
        }
コード例 #2
0
        public async Task <IActionResult> Vote(AddVoteCommand command)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                throw new ArgumentException("User not found");
            }

            try
            {
                command.UserId = user.Id;
                await _mediator.Send(command);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "{Message} {UserId} {TopicId} {OptionId}",
                                 "Failed at creating vote for topic", user.Id, command.TopicId, command.OptionId);
                return(ErrorView(e.Message, HttpContext.TraceIdentifier));
            }

            return(RedirectToAction("Details", new { id = command.TopicId }));
        }
コード例 #3
0
ファイル: VoteController.cs プロジェクト: igorbmaciel/Poll
        public async Task <IActionResult> CreateAsync([FromBody] AddVoteCommand command)
        {
            var response = await _voteAppService.AddVote(command);

            return(CreateResponseOnPost(response, RouteResponseConsts.Vote));
        }