Exemple #1
0
        private void GetStageOneResults()
        {
            var response = _httpClient.GetAsync("worldcups/2018/results").Result;

            if (response.IsSuccessStatusCode)
            {
                var liveResults =
                    JsonConvert.DeserializeObject <IEnumerable <Group> >(response.Content.ReadAsStringAsync().Result);

                //order matches based on this layout

                //matches.append([group[0], group[1]])
                //matches.append([group[2], group[3]])
                //matches.append([group[0], group[2]])
                //matches.append([group[3], group[1]])
                //matches.append([group[3], group[0]])
                //matches.append([group[1], group[2]])


                var groupMatches   = new Dictionary <int, IEnumerable <Match> >();
                var currentResults = liveResults.ToList();

                char groupLetter = 'A';
                foreach (object[] tournamentGroup in _tournament.GetGroups())
                {
                    var liveGroup = currentResults.FirstOrDefault(g => g.Letter == groupLetter);

                    if (liveGroup != null && liveGroup.Matches.Any())
                    {
                        var teamOne   = tournamentGroup[0].ToString();
                        var teamTwo   = tournamentGroup[1].ToString();
                        var teamThree = tournamentGroup[2].ToString();
                        var teamFour  = tournamentGroup[3].ToString();

                        var matches = new Queue <Match>();
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamOne, teamTwo)));
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamThree, teamFour)));
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamOne, teamThree)));
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamFour, teamTwo)));
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamFour, teamOne)));
                        matches.Enqueue(liveGroup.Matches.FirstOrDefault(m => IsCorrectMatch(m, teamTwo, teamThree)));

                        groupMatches.Add(liveGroup.Id, matches);
                    }

                    groupLetter++;
                }

                currentResults.ForEach(g =>
                {
                    if (g.Matches.Any())
                    {
                        g.Matches = groupMatches[g.Id].ToList();
                    }
                });

                Groups    = currentResults;
                _stageOne = null;
            }
        }