Пример #1
0
        private async Task RefreshMatchData(string action, string message)
        {
            try
            {
                string[] textArray = message.Split(';');
                string   matchID   = textArray[0];
                Match    match     = await _viewModel.GetMatchByIDAsync(matchID);

                if (match != null)
                {
                    Match findMatch = _viewModel.AllMatches?.FirstOrDefault(x => x.MatchID == match?.MatchID);
                    if (findMatch != null)
                    {
                        int findMatchIndex = _viewModel.AllMatches.IndexOf(findMatch);
                        _viewModel.AllMatches?.Insert(findMatchIndex, match);
                        _viewModel.AllMatches?.Remove(findMatch);
                    }
                    else
                    {
                        _viewModel.AllMatches?.Add(match);
                    }

                    if (match.StatusID != findMatch?.StatusID)
                    {
                        await _viewModel.GetStandingsAsync();
                    }
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        PopulatePageView(_viewModel.SelectedLiveMatch.MatchID == match?.MatchID);
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Пример #2
0
        private void UpdateMatch(string matchID, MatchDetails matchDetails)
        {
            try
            {
                Match match = matchDetails?.Match;
                if (match != null)
                {
                    var   allmatches            = new ObservableCollection <Match>(_viewModel.AllMatches);
                    var   allMatchesWithDetails = new ObservableCollection <MatchDetails>(_viewModel.AllMatchesWithDetails);
                    Match findMatch             = allmatches?.FirstOrDefault(x => x.MatchID == match?.MatchID);
                    if (findMatch != null)
                    {
                        // UPDATE MATCH
                        allmatches.Remove(findMatch);
                        allmatches.Add(match);
                        _viewModel.AllMatches = new ObservableCollection <Match>(allmatches);

                        // REMOVE MATCH
                        if (match.StatusID > 14)
                        {
                            allmatches?.Remove(findMatch);
                            _viewModel.AllMatches = new ObservableCollection <Match>(allmatches);
                        }

                        MatchDetails findMatchDetails = _viewModel.AllMatchesWithDetails.FirstOrDefault(x => x?.Match?.MatchID == findMatch?.MatchID);
                        if (findMatchDetails != null)
                        {
                            // UPDATE MATCH DETAILS
                            findMatchDetails.Match          = match;
                            findMatchDetails.PlayersOfMatch = new ObservableCollection <PlayerOfMatch>(matchDetails.PlayersOfMatch);
                            findMatchDetails.EventsOfMatch  = new ObservableCollection <EventOfMatch>(matchDetails.EventsOfMatch);
                            findMatchDetails.IsDataLoaded   = true;

                            // REMOVE MATCH DETAILS
                            if (match.StatusID > 14)
                            {
                                allMatchesWithDetails.Remove(findMatchDetails);
                                _viewModel.AllMatchesWithDetails = new ObservableCollection <MatchDetails>(allMatchesWithDetails);
                                _viewModel.SetMatchesBySelectedDate();
                            }
                        }
                    }
                    else
                    {
                        // ADD MATCH
                        allmatches?.Add(match);
                        _viewModel.AllMatches = new ObservableCollection <Match>(allmatches);

                        // ADD MATCH DETAILS
                        allMatchesWithDetails.Add(matchDetails);
                        _viewModel.AllMatchesWithDetails = new ObservableCollection <MatchDetails>(allMatchesWithDetails);
                        _viewModel.SetMatchesBySelectedDate();
                    }

                    if (match.StatusID != findMatch.StatusID || match.HomeTeamScore != findMatch.HomeTeamScore || match.AwayTeamScore != findMatch.AwayTeamScore)
                    {
                        _ = _viewModel.GetStandingsAsync();
                        _ = _viewModel.GetCompetitionStatisticsAsync();
                    }
                    _viewModel.TimeCounter.MatchesTime(_viewModel);
                }
            }
            catch (Exception ex)
            {
                _ = ReloadAsync(LoadDataType.FullData);
                Console.WriteLine($"Error: {ex.Message}");
            }
        }