Beispiel #1
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));
        }
        public async Task <SeasonInfoView> GetSeasonInfoView()
        {
            var view = new SeasonInfoView();
            //TODO: Uncomment when testing
            //var seasonInfoTask = _seasonInfoRepository.GetAllSeasonsAsync();

            //var seasons = (await seasonInfoTask).OrderByDescending(x => x.SeasonStartDate).ToList();
            //var seasonInfo = seasons[1];

            //TODO: Uncomment when ready to push
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var rostersTask = GetAllRosters(seasonInfo);

            var divisions = (await _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id)).ToList();

            try
            {
                var rosters = (await rostersTask).ToList();

                foreach (var rosterView in rosters)
                {
                    var division = divisions.First(x =>
                                                   x.LowerLimit <= rosterView.TeamTierScore && x.UpperLimit >= rosterView.TeamTierScore);
                    rosterView.Division = new DivisionView
                    {
                        DivisionName     = division.Name,
                        DivisionMinScore = division.LowerLimit,
                        DivisionId       = division.Id
                    };
                }

                view.Rosters = rosters.OrderByDescending(x => x.Division.DivisionMinScore).ToList();
            }
            catch (Exception)
            {
                //no rosters finalized yet
            }

            view.SeasonInfo = new SeasonInfoViewPartial
            {
                SeasonInfoId           = seasonInfo.Id,
                ClosedRegistrationDate = seasonInfo.ClosedRegistrationDate,
                SeasonName             = seasonInfo.SeasonName,
                SeasonStartDate        = seasonInfo.SeasonStartDate
            };
            return(view);
        }
        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);
        }
Beispiel #4
0
        private async Task <bool> UpdateStatsAsync(MatchSubmissionView view, SummonerInfoEntity userPlayer)
        {
            var divisionTask = _scheduleService.GetDivisionIdByScheduleAsync(view.ScheduleId);
            var matchesTask  = _matchDetailRepository.ReadForScheduleId(view.ScheduleId);
            var seasonInfo   = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var registeredPlayersTask  = _summonerInfoRepository.GetAllValidSummonersAsync();
            var previousListedMvpsTask = _matchMvpRepository.ReadAllForTeamScheduleId(view.ScheduleId);
            var registeredPlayers      = (await registeredPlayersTask).ToDictionary(x => x.SummonerName.ToLowerInvariant(), x => x);
            var matchDictionary        = (await matchesTask);
            var mvpDetails             = (await previousListedMvpsTask).OrderBy(x => x.Game).ToDictionary(x => x.Game, x => x);

            var divisionId       = await divisionTask;
            var insertMvpDetails = new List <MatchMvpEntity>();
            var updateMvpDetails = new List <MatchMvpEntity>();
            //Will always insert new records and never update, we will delete any old records first
            var insertDetailsList      = new List <MatchDetailEntity>();
            var insertStatsList        = new List <PlayerStatsEntity>();
            var championDetails        = new List <ChampionStatsEntity>();
            var insertAchievementsList = new List <AchievementEntity>();

            //List of Ids to hard delete

            foreach (var gameInfo in view.GameInfos)
            {
                if (gameInfo.HomeTeamForfeit || gameInfo.AwayTeamForfeit)
                {
                    continue;
                }

                //matchhistory.na.leagueoflegends.com/en/#match-details/NA1/{match id}/{dont care}?tab=overview
                var split = gameInfo.MatchHistoryLink.Split("/");
                //If an invalid match was submitted, will fail the entire process
                if (!uint.TryParse(split[6], out var matchId))
                {
                    return(false);
                }

                var version       = (await GlobalVariables.ChampsApi.Versions.GetAllAsync()).First();
                var championsTask = GlobalVariables.ChampsApi.Champions.GetAllAsync(version);
                var riotMatchTask = GlobalVariables.Api.Match.GetMatchAsync(RiotSharp.Misc.Region.Na, matchId);

                var riotMatch = await riotMatchTask;
                var champions = await championsTask;

                CollectBans(view, riotMatch, champions, seasonInfo, divisionId, championDetails);

                var gameDuration = riotMatch.GameDuration;

                var matchList = new List <MatchDetailContract>();

                await CollectPlayerMatchDetailsAsync(view, riotMatch, champions, gameInfo, registeredPlayers, gameDuration, seasonInfo, matchDictionary,
                                                     matchList, divisionId, championDetails);

                CollectMatchMvpData(view, matchList, registeredPlayers, gameInfo, mvpDetails, updateMvpDetails, insertMvpDetails, userPlayer);

                insertDetailsList.AddRange(matchList.Select(x => x.MatchDetail));
                insertStatsList.AddRange(matchList.Select(x => x.PlayerStats));
                insertAchievementsList.AddRange(matchList.SelectMany(x => x.Achievements));
            }

            if (!await DeleteOldRecords(view))
            {
                return(false);
            }

            var insertAchievementsResult = await _achievementRepository.InsertAsync(insertAchievementsList);

            var insertMvpResult = await _matchMvpRepository.CreateAsync(insertMvpDetails);

            var updateMvpResult = await _matchMvpRepository.UpdateAsync(updateMvpDetails);

            var insertStatsResult = await _playerStatsRepository.InsertAsync(insertStatsList);

            var insertDetailsResult = await _matchDetailRepository.InsertAsync(insertDetailsList);

            var insertChampionStatsResult = await _championStatsRepository.CreateAsync(championDetails);

            return(insertStatsResult && insertDetailsResult && insertMvpResult && updateMvpResult && insertChampionStatsResult && insertAchievementsResult);
        }
        public async Task <SummonerRequestView> GetRequestedSummonersAsync(UserEntity user)
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var summoners      = (await _summonerInfoRepository.GetAllValidSummonersAsync()).ToList();
            var summonerEntity = summoners.First(x => x.UserId == user.Id);

            summoners.Remove(summonerEntity);
            if (summonerEntity.IsAcademyPlayer)
            {
                summoners = summoners.Where(x => x.IsAcademyPlayer).ToList();
            }

            var requestedSummonerEntities = (await _requestedSummonerRepository.ReadAllForSummonerAsync(summonerEntity.Id, seasonInfo.Id)).ToList();
            var view = new SummonerRequestView
            {
                SummonerName  = summonerEntity.SummonerName,
                SummonerNames = summoners.Select(x => x.SummonerName).OrderBy(x => x).ToList(),
                Names         = GetSelectListItems(summoners.Select(x => x.SummonerName).OrderBy(x => x))
            };

            if (!requestedSummonerEntities.Any())
            {
                var count = RequestingSummonerCount;
                if (summonerEntity.IsAcademyPlayer)
                {
                    count = 1;
                }
                view.RequestedSummoners.AddRange(AddEmptyRequestedSummonerViews(count));
            }
            else
            {
                var requestedSummoners = new List <RequestedSummoner>();

                foreach (var entity in requestedSummonerEntities)
                {
                    var summoner = summoners.First(x => x.Id == entity.SummonerRequestedId);
                    requestedSummoners.Add(new RequestedSummoner
                    {
                        SummonerName = summoner.SummonerName,
                        IsSub        = entity.IsSub
                    });
                }

                view.RequestedSummoners = requestedSummoners;

                var missingCount = RequestingSummonerCount - view.RequestedSummoners.Count;
                if (summonerEntity.IsAcademyPlayer)
                {
                    missingCount = 1 - view.RequestedSummoners.Count;
                }

                view.RequestedSummoners.AddRange(AddEmptyRequestedSummonerViews(missingCount));
            }

            if (!summonerEntity.IsAcademyPlayer)
            {
                SetIsSubToElements(view);
            }

            return(view);
        }