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}"); } }