public async Task <string> Handle(CreateParticipationCommand request, CancellationToken cancellationToken)
        {
            var tournamentNavigation =
                await _readTournamentRepository.GetOneTournamentNavigationById(request.TournamentId);

            if (tournamentNavigation is null)
            {
                throw new NotFoundException(request.TournamentId.ToString(), "Tournament");
            }
            var stepNavigation = await _readStepRepository.GetOneStepNavigationById(request.StepId);

            if (stepNavigation is null)
            {
                throw new NotFoundException(request.StepId.ToString(), "Step");
            }
            var teamNavigation = await _readTeamRepository
                                 .GetOneTeamNavigationByIdAsync(request.TeamId);

            if (teamNavigation is null)
            {
                throw new NotFoundException(request.TeamId.ToString(), "Team");
            }
            if (await _readParticipationRepository.ParticipationExistsByTournamentStepTeamIds(request.TournamentId,
                                                                                              request.StepId, request.TeamId))
            {
                throw new ApplicationException(
                          $"Participation for team : {request.TeamId} on tournament : {request.TournamentId} on step : {request.StepId} already exists");
            }

            if (!await CanAddParticipation(request.TeamId, request.TournamentId, request.StepId))
            {
                throw new ApplicationException("Participation cannot be created, finish previous first");
            }

            var team = new TeamEntity(new TeamId(request.TeamId),
                                      teamNavigation.MembersIds.Select(memberId => new UserId(memberId)).ToList());
            var step = new StepEntity(new StepId(request.StepId),
                                      stepNavigation.TournamentsIds.Select(tournamentId => new TournamentId(tournamentId)).ToList());
            var tournament =
                new TournamentEntity(new TournamentId(request.TournamentId), tournamentNavigation.IsPublished);
            var participation = ParticipationAggregate.CreateNew(await _participationRepository.NextIdAsync(), team,
                                                                 tournament, step, _timeService.Now());

            await _participationRepository.SetAsync(participation);

            return(participation.Id.ToString());
        }
示例#2
0
 private static StepSessionEntity ToStepSessionEntity(StepEntity step, IList <TestNavigation> tests) =>