コード例 #1
0
        public async Task <SummonerTeamCreationView> GetSummonersToCreateTeamAsync()
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var summonersTask = _summonerInfoRepository.GetAllValidSummonersAsync();
            var rostersTask   = _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id);

            var summoners = (await summonersTask).Where(x => x.IsValidPlayer).ToList();
            var rosters   = await rostersTask;

            var view = new SummonerTeamCreationView
            {
                SummonerInfos = new List <SummonerInfo>()
            };
            var unassignedPlayers = summoners.ToList();

            foreach (var roster in rosters)
            {
                var summonerIds = (await _teamPlayerRepository.ReadAllForRosterAsync(roster.Id)).Select(x => x.SummonerId);
                foreach (var summonerId in summonerIds)
                {
                    var summoner = summoners.FirstOrDefault(x => x.Id == summonerId);
                    if (summoner != null)
                    {
                        unassignedPlayers.Remove(summoner);
                    }
                }
            }

            foreach (var unassignedPlayer in unassignedPlayers)
            {
                var info = new SummonerInfo
                {
                    SummonerId   = unassignedPlayer.Id,
                    SummonerName = unassignedPlayer.SummonerName
                };
                view.SummonerInfos.Add(info);
            }
            return(view);
        }
コード例 #2
0
        public async Task <Dictionary <string, List <ScheduleView> > > GetAllSchedules()
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var divisionsTask = _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id);
            var schedulesTask = _scheduleRepository.GetAllAsync(seasonInfo.Id);
            var rostersTask   = _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id);

            var rosters   = (await rostersTask).ToDictionary(x => x.Id, x => x);
            var divisions = (await divisionsTask).ToList();
            var schedules = (await schedulesTask).ToList();


            return(SetupSchedule(rosters, divisions, schedules));
        }
コード例 #3
0
        /// <summary>
        /// For Admin usage only
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <RosterView> > GetAllRosters(SeasonInfoEntity seasonInfo = null)
        {
            var list = new List <RosterView>();

            if (seasonInfo == null)
            {
                seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();
            }
            var rostersTask           = _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id);
            var captainsTask          = _teamCaptainRepository.GetAllTeamCaptainsAsync();
            var alternateAccountsTask = _alternateAccountRepository.ReadAllAsync();
            var allPlayersTask        = _teamPlayerRepository.ReadAllForSeasonAsync(seasonInfo.Id);

            var rosters           = await rostersTask;
            var captains          = (await captainsTask).ToList();
            var alternateAccounts = (await alternateAccountsTask).ToList();
            var allPlayers        = (await allPlayersTask).ToList();

            foreach (var roster in rosters)
            {
                var players = allPlayers.Where(x => x.TeamRosterId == roster.Id).ToList();
                var captain = captains.FirstOrDefault(x => x.TeamRosterId == roster.Id);

                var summoners =
                    (await _summonerInfoRepository.GetAllForSummonerIdsAsync(players.Select(x => x.SummonerId))).ToList();

                var alts          = alternateAccounts.Where(x => summoners.Select(y => y.Id).ToList().Contains(x.SummonerId));
                var summonerViews = _summonerMapper.MapDetailed(summoners, alts, new List <PlayerStatsView>()).ToList();
                foreach (var teamPlayerEntity in players)
                {
                    var player = summoners.First(x => x.Id == teamPlayerEntity.SummonerId);

                    var isSub        = teamPlayerEntity.IsSub ?? false;
                    var summonerView = summonerViews.First(x => x.SummonerName == player.SummonerName);
                    summonerView.IsSub = isSub;
                }

                var rosterView = new RosterView
                {
                    RosterId      = roster.Id,
                    Captain       = summoners.FirstOrDefault(x => x.Id == captain?.SummonerId)?.SummonerName,
                    TeamName      = roster.TeamName,
                    Wins          = roster.Wins ?? 0,
                    Loses         = roster.Loses ?? 0,
                    Points        = roster.Points ?? 0,
                    Players       = summonerViews,
                    TeamTierScore = roster.TeamTierScore.GetValueOrDefault()
                };

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/logos", roster.Id.ToString());
                if (File.Exists(path))
                {
                    var byteData = await File.ReadAllBytesAsync(path);

                    var base64 = Convert.ToBase64String(byteData);
                    var type   = GetContentType(path);
                    var imgSrc = String.Format($"data:{type};base64,{base64}");
                    rosterView.FileSource = imgSrc;
                }
                rosterView.Cleanup();
                list.Add(rosterView);
            }

            return(list);
        }
コード例 #4
0
        public async Task <FpSummonerView> GetFpSummonerView()
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var summoners      = (await _summonerInfoRepository.GetAllSummonersAsync()).ToDictionary(x => x.Id, x => x);
            var teams          = (await _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id)).ToDictionary(x => x.Id, x => x);
            var blackLists     = (await _blacklistRepository.GetAllAsync()).ToDictionary(x => x.UserId, x => x);
            var usedSummoners  = new Dictionary <Guid, SummonerInfoEntity>();
            var fpSummonerView = new FpSummonerView();

            foreach (var team in teams)
            {
                var players = ((await _teamPlayerRepository.ReadAllForRosterAsync(team.Key))).Where(x => x.SeasonInfoId == seasonInfo.Id).ToList();
                foreach (var player in players)
                {
                    if (summoners.TryGetValue(player.SummonerId, out var summoner) && !usedSummoners.TryGetValue(player.SummonerId, out _))
                    {
                        usedSummoners.Add(player.SummonerId, summoner);
                        var mapped = _summonerMapper.Map(summoner);

                        if (!blackLists.TryGetValue(mapped.UserId, out var blackList))
                        {
                            fpSummonerView.SummonerInfos.Add(new FpSummonerInfo
                            {
                                UserId       = summoner.UserId,
                                RosterId     = team.Key,
                                SummonerName = summoner.SummonerName,
                                Role         = mapped.Role,
                                OffRole      = mapped.OffRole,
                                TierDivision = mapped.TierDivision,
                                PreviousSeasonTierDivision = mapped.PreviousSeasonTierDivision,
                                OpGgUrl         = summoner.OpGGUrlLink,
                                TeamName        = team.Value.TeamName,
                                IsRegistered    = summoner.IsValidPlayer,
                                IsEsubOnly      = mapped.IsSubOnly,
                                IsAcademyPlayer = mapped.IsAcademyPlayer,
                                DiscordHandle   = mapped.DiscordHandle
                            });
                        }
                    }
                    else
                    {
                        _logger.LogError($"Dupe player alert for: {summoner?.SummonerName ?? player.SummonerId.ToString()}");
                    }
                }
            }

            var remainingSummoners = summoners.Except(usedSummoners).Concat(usedSummoners.Except(summoners));

            foreach (var remainingSummoner in remainingSummoners)
            {
                var mapped = _summonerMapper.Map(remainingSummoner.Value);
                if (!blackLists.TryGetValue(mapped.UserId, out var blackList))
                {
                    fpSummonerView.SummonerInfos.Add(new FpSummonerInfo
                    {
                        UserId       = remainingSummoner.Value.UserId,
                        SummonerName = mapped.SummonerName,
                        Role         = mapped.Role,
                        OffRole      = mapped.OffRole,
                        TierDivision = mapped.TierDivision,
                        PreviousSeasonTierDivision = mapped.PreviousSeasonTierDivision,
                        OpGgUrl         = mapped.OpGgUrl,
                        TeamName        = "Unassigned",
                        IsEsubOnly      = mapped.IsSubOnly,
                        IsRegistered    = mapped.IsValid,
                        IsAcademyPlayer = mapped.IsAcademyPlayer,
                        DiscordHandle   = mapped.DiscordHandle
                    });
                }
            }

            return(fpSummonerView);
        }