public async Task <AddVoteResponse> AddVote(AddVoteCommand command) { var response = await _mediator.Send(command); if (Notification.HasNotification()) { return(null); } return(response); }
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 })); }
public async Task <IActionResult> CreateAsync([FromBody] AddVoteCommand command) { var response = await _voteAppService.AddVote(command); return(CreateResponseOnPost(response, RouteResponseConsts.Vote)); }