Exemplo n.º 1
0
        public async Task HandleAsync(JoinLeague command, ICorrelationContext context)
        {
            PlayerInternalIdDto playerIdDto = await _playersService.GetInternalIdAsync(command.PlayerExternalId);

            if (playerIdDto is null)
            {
                throw new FliGenException(ErrorCodes.NoPlayerWithSuchExternalId, $"There is no player with external id: {command.PlayerExternalId}");
            }

            int playerId = playerIdDto.InternalId;

            var leagueSettingsRepo = _uow.GetRepositoryAsync <Domain.Entities.LeagueSettings>();

            Domain.Entities.LeagueSettings leagueSettings =
                await leagueSettingsRepo.SingleAsync(x => x.LeagueId == command.LeagueId);

            if (leagueSettings is null)
            {
                throw new FliGenException(ErrorCodes.NoLeagueSettings, $"There is no league settings for league: {command.LeagueId}");
            }

            var lplinksRepo = _uow.GetRepositoryAsync <LeaguePlayerLink>();

            LeaguePlayerLink lastLink = await
                                        lplinksRepo.SingleAsync(x =>
                                                                x.PlayerId == playerId &&
                                                                x.LeagueId == command.LeagueId &&
                                                                x.Actual);

            if (lastLink is null || lastLink.InLeftStatus())
            {
                LeaguePlayerLink link = leagueSettings.RequireConfirmation
                            ? LeaguePlayerLink.CreateWaitingLink(command.LeagueId, playerId)
                            : LeaguePlayerLink.CreateJoinedLink(command.LeagueId, playerId);

                if (leagueSettings.RequireConfirmation)
                {
                    LeaguePlayerLink.CreateWaitingLink(command.LeagueId, playerId);
                }
                else
                {
                    LeaguePlayerLink.CreateJoinedLink(command.LeagueId, playerId);
                }

                await lplinksRepo.AddAsync(link);
            }
Exemplo n.º 2
0
        public async Task HandleAsync(UpdateLeagueSettings command, ICorrelationContext context)
        {
            var repo = _uow.GetRepositoryAsync <Domain.Entities.LeagueSettings>();

            Domain.Entities.LeagueSettings leagueSettings = await repo.SingleAsync(x => x.LeagueId == command.LeagueId);

            if (leagueSettings is null)
            {
                throw new FliGenException(ErrorCodes.NoLeagueSettings, $"There is no league settings for league: {command.LeagueId}");
            }

            repo.UpdateAsync(Domain.Entities.LeagueSettings.GetUpdated(
                                 leagueSettings,
                                 command.Visibility,
                                 command.RequireConfirmation,
                                 command.PlayersInTeam,
                                 command.TeamsInTour));

            _uow.SaveChanges();
            await _busPublisher.PublishAsync(new LeagueSettingsUpdated(command.LeagueId), context);
        }