private List <SummaryEventOfMatch> GetCommentary(MatchDetails matchDetails) { List <SummaryEventOfMatch> summaryEventOfMatchesList = new List <SummaryEventOfMatch>(); var eventsList = matchDetails.EventsOfMatch?.Where(x => x != null).ToList(); int homeScore = 0; int awayScore = 0; foreach (var eventOfMatch in eventsList ?? new List <EventsOfMatches>()) { SummaryEventOfMatch summaryEventOfMatch = new SummaryEventOfMatch() { EventOfMatch = eventOfMatch, HomeTeam = eventOfMatch.EventTeam == matchDetails.Match.HomeTeam ? eventOfMatch.EventTeam : null, AwayTeam = eventOfMatch.EventTeam == matchDetails.Match.AwayTeam ? eventOfMatch.EventTeam : null, EventMinute = eventOfMatch.EventMinute, EventName = eventOfMatch.EventName, HomeTeamScore = 0, AwayTeamScore = 0 }; if (IsGoal(eventOfMatch)) { if (eventOfMatch.EventTeam.ToUpper().Trim() == matchDetails.Match.HomeTeam.ToUpper().Trim()) { homeScore += 1; } if (eventOfMatch.EventTeam.ToUpper().Trim() == matchDetails.Match.AwayTeam.ToUpper().Trim()) { awayScore += 1; } } summaryEventOfMatch.HomeTeamScore = homeScore; summaryEventOfMatch.AwayTeamScore = awayScore; summaryEventOfMatchesList.Add(summaryEventOfMatch); } summaryEventOfMatchesList.Reverse(); return(summaryEventOfMatchesList); }
internal List <SummaryEventOfMatch> GetSummaryEventsList(MatchDetails matchDetails) { List <SummaryEventOfMatch> summaryEventOfMatchesList = new List <SummaryEventOfMatch>(); Matches selectedMatch = matchDetails.Match; var homeTeamPlayers = matchDetails.PlayersOfMatch?.Where(x => x.TeamName.Trim() == selectedMatch.HomeTeam.Trim()); var awayTeamPlayers = matchDetails.PlayersOfMatch?.Where(x => x.TeamName.Trim() == selectedMatch.AwayTeam.Trim()); var eventsList = matchDetails.EventsOfMatch?.Where(x => x.EventName == "GOAL" || x.EventName == "OWNGOAL" || x.EventName == "PENALTYSCORED" || x.EventName == "PENALTYMISSED" || x.EventName == "YELLOW" || x.EventName == "RED" || x.EventName == "BIGCHANCE" //|| x.EventName == "SUBSTITUTION" || x.EventName == "ASSIST").ToList(); int homeScore = 0; int awayScore = 0; foreach (var eventOfMatch in eventsList ?? new List <EventsOfMatches>()) { SummaryEventOfMatch summaryEventOfMatch = new SummaryEventOfMatch() { EventOfMatch = eventOfMatch, HomeTeamScore = 0, AwayTeamScore = 0, HomeTeam = eventOfMatch?.EventTeam == selectedMatch.HomeTeam ? selectedMatch.HomeTeam : string.Empty, AwayTeam = eventOfMatch?.EventTeam == selectedMatch.AwayTeam ? selectedMatch.AwayTeam : string.Empty, EventName = eventOfMatch?.EventName, EventMinute = eventOfMatch?.EventMinute, }; PlayersOfMatches mainPlayerOfMatch = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == eventOfMatch.MainPlayerOfMatchId); string mainPlayerFullName = (mainPlayerOfMatch?.FirstName?.Trim() + " " + mainPlayerOfMatch?.Lastname?.Trim())?.Trim(); PlayersOfMatches secondPlayerOfMatch = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == eventOfMatch.SecondPlayerOfMatchId); string secondPlayerFullName = (secondPlayerOfMatch?.FirstName?.Trim() + " " + secondPlayerOfMatch?.Lastname?.Trim())?.Trim(); if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim()) { summaryEventOfMatch.HomeMainPlayer = mainPlayerFullName; summaryEventOfMatch.HomeSecondPlayer = secondPlayerFullName; } else { summaryEventOfMatch.AwayMainPlayer = mainPlayerFullName; summaryEventOfMatch.AwaySecondPlayer = secondPlayerFullName; } summaryEventOfMatch.HomeTeamVisible = !string.IsNullOrEmpty(summaryEventOfMatch.HomeTeam); summaryEventOfMatch.AwayTeamVisible = !string.IsNullOrEmpty(summaryEventOfMatch.AwayTeam); if (IsGoal(eventOfMatch)) { if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim()) { homeScore += 1; } if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim()) { awayScore += 1; } } summaryEventOfMatch.HomeTeamScore = homeScore; summaryEventOfMatch.AwayTeamScore = awayScore; if (eventOfMatch.EventName == "GOAL") { int eventIndex = eventsList.IndexOf(eventOfMatch); if (eventIndex + 1 < eventsList.Count) { EventsOfMatches nextEvent = eventsList[eventIndex + 1]; if (nextEvent.EventName == "ASSIST") { PlayersOfMatches assistPlayerOfMatch = matchDetails.PlayersOfMatch.Find(x => x.PlayerOfMatchId == nextEvent.MainPlayerOfMatchId); string assistPlayerFullName = (assistPlayerOfMatch?.FirstName?.Trim() + " " + assistPlayerOfMatch?.Lastname?.Trim())?.Trim(); if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim()) { summaryEventOfMatch.HomeSecondPlayer = assistPlayerFullName; } if (eventOfMatch.EventTeam.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim()) { summaryEventOfMatch.AwaySecondPlayer = assistPlayerFullName; } } } } summaryEventOfMatchesList.Add(summaryEventOfMatch); } return(summaryEventOfMatchesList.ToList()); }