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); }
public async Task <ActionResult <SummonerModel> > GetSummonerByName(string platformId, string summonerName, [FromQuery] bool includeMatches = true, [FromQuery] bool includeLeagues = true, [FromQuery] bool includeMatchDetails = false) { var summoner = await _riotService.GetSummoner(platformId, summonerName); if (summoner == null) { return(NotFound("Summoner with given name could not be find")); } if (includeMatches) { var matchOverviews = await _riotService.GetMatchesByAccount(platformId, summoner.AccountId !) ?? new List <MatchOverviewModel>(); if (includeMatchDetails) { summoner.MatchesWithDetails = await _riotService.GetMatchDetails(platformId, matchOverviews); } else { summoner.Matches = matchOverviews; } } if (includeLeagues) { summoner.Leagues = await _riotService.GetLeaguesBySummoner(platformId, summoner.Id !); } return(summoner); }
public async Task <ActionResult> GetSummoner(string summonerName) { try { return(Ok(await _riotService.GetSummoner(summonerName))); } catch (HttpRequestException ex) { return(BadRequest(ex)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }