public async Task <List <MatchDetail> > GetSummonerMatchesAsync(string summonerName, int page, int[] queues, int[] seasons)
        {
            // In case of not sending any queue all valid queues are used.
            queues = (queues.Length == 0 ? validQueues : queues);

            var summonerData = await _riotService.GetSummoner(summonerName);

            int beginIndex = page;
            int endIndex   = page * _maxMatchesPerRequest;

            if (beginIndex == 1)
            {
                endIndex   = _maxMatchesPerRequest;
                beginIndex = 0;
            }
            else
            {
                endIndex   = page * _maxMatchesPerRequest;
                beginIndex = endIndex - _maxMatchesPerRequest;
            }

            var result = new MatchesList
            {
                Matches = new List <Match>()
            };

            foreach (int queue in queues)
            {
                if (seasons.Length > 0)
                {
                    foreach (int season in seasons)
                    {
                        MatchesList summonerMatches;
                        if (season == 14)
                        {
                            summonerMatches = await _riotService.GetSummonerMatches(summonerData.AccountId, queue, 13, 1578668400000, beginIndex, endIndex);
                        }
                        else
                        {
                            summonerMatches = await _riotService.GetSummonerMatches(summonerData.AccountId, queue, season, beginIndex, endIndex);
                        }
                        result.Matches.AddRange(summonerMatches.Matches);
                        result.TotalGames += summonerMatches.TotalGames;
                    }
                }
                else
                {
                    MatchesList summonerMatches = await _riotService.GetSummonerMatches(queue, summonerData.AccountId, beginIndex, endIndex);

                    result.Matches.AddRange(summonerMatches.Matches);
                    result.TotalGames += summonerMatches.TotalGames;
                }
            }
            result.Matches = new List <Match>(result.Matches.OrderByDescending(c => c.Timestamp));
            var matchesDetails = await GetMatchDetailsListAsync(result);

            await _matchDetailDao.InsertMany(matchesDetails);

            return(matchesDetails);
        }
Exemplo n.º 2
0
 public async Task <ActionResult> GetMatches(string accountId, [FromQuery] int queue = 420, [FromQuery] int season = 13, [FromQuery] long beginTime = 1578668400000, [FromQuery] int beginIndex = 0, [FromQuery] int endIndex = 100)
 {
     try
     {
         return(Ok(await _riotService.GetSummonerMatches(accountId, queue, season, beginTime, beginIndex, endIndex)));
     }
     catch (HttpRequestException ex)
     {
         return(BadRequest(ex));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }