private async Task UpdateSummonerAsync(Summoner summoner)
        {
            if (summoner == null)
                throw new ArgumentNullException("summoner");

            if (summoner.LeagueInfo == null)
                throw new InvalidOperationException("summoner.LeagueInfo is null");

            var leagues = await _riot.GetLeaguesAsync(summoner.Region, summoner.SummonerId);
            var solo = leagues?.FirstOrDefault(league => league.Queue == QueueType.RANKED_SOLO_5x5);

            if (solo == null)
            {
                summoner.LeagueInfo.Division = 0;
                summoner.LeagueInfo.Tier = TierName.Unranked;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
            else
            {
                var entry = solo.Entries.First(e => e.PlayerOrTeamId == summoner.SummonerId.ToString());

                if (entry == null)
                    throw new InvalidOperationException("Entry not found in league.");

                var division = (int)entry.Division;
                var tier = (TierName)Enum.Parse(typeof(TierName), solo.Tier.ToString(), true);
                summoner.LeagueInfo.Division = division;
                summoner.LeagueInfo.Tier = tier;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
        }
 public async Task<bool> UpdateLeagueAsync(Summoner summoner, TierName tier, int division)
 {
     summoner.LeagueInfo.Division = division;
     summoner.LeagueInfo.Tier = tier;
     summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
     return await UnitOfWork.SaveChangesAsync() > 0;
 } 
 public async Task<bool> SetActiveSummonerAsync(Summoner summoner)
 {
     foreach (var s in summoner.User.Summoners)
     {
         s.IsActive = false;
     }
     summoner.IsActive = true;
     return await UnitOfWork.SaveChangesAsync() > 0;
 }
Example #4
0
        private async Task UpdateSummonerAsync(Summoner summoner)
        {
            if (summoner == null)
            {
                throw new ArgumentNullException("summoner");
            }

            if (summoner.LeagueInfo == null)
            {
                throw new InvalidOperationException("summoner.LeagueInfo is null");
            }

            var leagues = await _riot.GetLeaguesAsync(summoner.Region, summoner.SummonerId);

            var solo = leagues?.FirstOrDefault(league => league.Queue == QueueType.RANKED_SOLO_5x5);

            if (solo == null)
            {
                summoner.LeagueInfo.Division    = 0;
                summoner.LeagueInfo.Tier        = TierName.Unranked;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
            else
            {
                var entry = solo.Entries.First(e => e.PlayerOrTeamId == summoner.SummonerId.ToString());

                if (entry == null)
                {
                    throw new InvalidOperationException("Entry not found in league.");
                }

                var division = (int)entry.Division;
                var tier     = (TierName)Enum.Parse(typeof(TierName), solo.Tier.ToString(), true);
                summoner.LeagueInfo.Division    = division;
                summoner.LeagueInfo.Tier        = tier;
                summoner.LeagueInfo.UpdatedTime = DateTimeOffset.Now;
            }
        }