Esempio n. 1
0
        public async Task <MatchSet> GetMatchesForPlayer(string gamertag, int start = 0, int count = 10, params Enumeration.GameMode[] gameModes)
        {
            var query = new GetMatches().ForPlayer(gamertag).Skip(start).Take(count);

            if (gameModes != null && gameModes.Length > 0)
            {
                if (gameModes.Length == 1)
                {
                    query.InGameMode(gameModes[0]);
                }
                else
                {
                    query.InGameModes(gameModes.ToList());
                }
            }

            var matches = await _session.Query(query);

            foreach (var match in matches.Results)
            {
                match.Map = await _metadataRepository.GetMap(match.MapId);

                if (match.MapVariant != null && match.MapVariant.ResourceType == Enumeration.ResourceType.MapVariant &&
                    match.MapVariant.OwnerType == Enumeration.OwnerType.Official)
                {
                    match.MapVariantInfo = await _metadataRepository.GetMapVariant(match.MapVariant.ResourceId);
                }

                match.GameBaseVariant = await _metadataRepository.GetGameBaseVariant(match.GameBaseVariantId);

                if (match.GameVariant != null && match.GameVariant.ResourceType == Enumeration.ResourceType.GameVariant &&
                    match.GameVariant.OwnerType == Enumeration.OwnerType.Official)
                {
                    match.GameVariantInfo = await _metadataRepository.GetGameVariant(match.GameVariant.ResourceId);
                }

                if (match.HopperId.HasValue)
                {
                    match.Playlist = await _metadataRepository.GetPlaylist(match.HopperId.Value);
                }

                if (match.SeasonId.HasValue)
                {
                    match.Season = await _metadataRepository.GetSeason(match.SeasonId);
                }

                if (match.Teams != null)
                {
                    foreach (var team in match.Teams)
                    {
                        team.TeamColor = await _metadataRepository.GetTeamColor(team.Id);
                    }
                }
            }

            return(matches);
        }