Example #1
0
        public async Task <Option <TeamDetailsView, Error> > Handle(
            GetTeamDetails request,
            CancellationToken cancellationToken)
        {
            var team = await _teamRepository.GetByIdAsync(request.TeamId);

            if (team == null)
            {
                return(Option.None <TeamDetailsView, Error>(
                           Error.NotFound($"No team with id {request.TeamId} was found.")));
            }

            var result = _mapper.Map <Team, TeamDetailsView>(team);

            result.UserHasVoted = await _votesRepository
                                  .HasAnyByTeamAndUserAsync(request.TeamId, request.CurrentUserId);

            return(result.Some <TeamDetailsView, Error>());
        }
Example #2
0
 private Task <Option <Unit, Error> > SimilarVoteShouldNotExist(VoteForTeam command) =>
 _votesRepository.HasAnyByTeamAndUserAsync(command.TeamId, command.UserId)
 .SomeWhenAsync(b => !b, Error.Conflict($"Similar vote already exists."))
 .MapAsync(_ => Task.FromResult(Unit.Value));