public async Task <Unit> Handle(AddVoteCommand request, CancellationToken cancellationToken) { if (!_topicsRepository.DoesTopicExist(request.TopicId)) { throw new ArgumentException($"Topic with id {request.TopicId} doesn't exist"); } if (_votesRepository.HadUserVote(request.TopicId, request.UserId)) { throw new ArgumentException($"User with id {request.UserId} had already voted"); } if (!_optionsRepository.DoesOptionExist(request.OptionId)) { throw new ArgumentException($"Option with id {request.OptionId} doesn't exist"); } var vote = _mapper.Map <Vote>(request); await _votesRepository.CreateAsync(vote); _logger.LogInformation("{Message} {VoteId} {OptionName} {TopicName} {CreatedBy}", "Created vote in topic", vote.Id, vote.Option.Name, vote.Topic.Title, vote.User.UserName); return(Unit.Value); }