Beispiel #1
0
        public async Task <IEnumerable <PlayerWithRate> > GetAsync([FromQuery] PlayersQuery query)
        {
            query.PlayerId ??= Array.Empty <int>();
            query.LeagueId ??= Array.Empty <int>();

            return(await _playersService.GetAsync(query));
        }
Beispiel #2
0
        public async Task HandleAsync(TeamsCreated @event, ICorrelationContext context)
        {
            int[] playerIds = @event.Teams.SelectMany(inner => inner).ToArray();

            var query = new PlayersQuery
            {
                LeagueId  = new [] { @event.LeagueId },
                PlayerId  = playerIds,
                QueryType = PlayersQueryType.Actual,
                Page      = 1,
                Size      = playerIds.Length
            };

            List <PlayerWithRateDto> playersInfo = (await _playersService.GetAsync(query)).ToList();

            int teamNumber = 1;

            foreach (var team in @event.Teams)
            {
                var body = CreateTeamAndRateBody(team, playersInfo, teamNumber);

                InboxNotification notification = InboxNotificationBuilder
                                                 .Create()
                                                 .WithReceiver(team)
                                                 .WithSender("Notification service")
                                                 .WithTopic($"Teams for tour: {@event.TourId} in league: {@event.LeagueId} are formed!")
                                                 .WithBody($"{body}")
                                                 .Build();

                await _busPublisher.SendAsync(notification, context);

                teamNumber++;
            }

            int[] registeredPlayers =
                (await _toursService.GetAsync(new RegisteredOnTourPlayers {
                TourId = @event.TourId
            }))
                .Select(dto => dto.InternalId)
                .ToArray();
            int[] unhappyPlayers = registeredPlayers.Except(playerIds).ToArray();

            if (unhappyPlayers.Length != 0)
            {
                InboxNotification notification = InboxNotificationBuilder
                                                 .Create()
                                                 .WithReceiver(unhappyPlayers)
                                                 .WithSender("Notification service")
                                                 .WithTopic($"Teams for tour: {@event.TourId} in league: {@event.LeagueId} are formed!")
                                                 .WithBody("Sorry you are out of the game. Try next time!")
                                                 .Build();

                await _busPublisher.SendAsync(notification, context);
            }
        }
 private async Task <List <PlayerWithRateDto> > GetPlayersRate(GenerateTeams command)
 {
     return((await _playersService.GetAsync(
                 new PlayersQuery
     {
         Size = command.Pid.Length,
         PlayerId = command.Pid,
         QueryType = PlayersQueryType.Actual,
         LeagueId = new[] { command.LeagueId },
     })).ToList());
 }