コード例 #1
0
        public IActionResult PutPlayersOfMatches([FromQuery] int id, PlayersOfMatches playersOfMatches)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != playersOfMatches.PlayerOfMatchId)
            {
                return(BadRequest());
            }

            _dystirDBContext.Entry(playersOfMatches).State = EntityState.Modified;

            try
            {
                _dystirDBContext.SaveChanges();
                Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == playersOfMatches.MatchId);
                HubSend(match);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayersOfMatchesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(StatusCodes.Status204NoContent));
        }
コード例 #2
0
        private void SetPlayersListByEventsOfMatch(List <EventsOfMatches> eventsOfMatch, Matches selectedMatch)
        {
            if (selectedMatch != null)
            {
                selectedMatch.HomeTeamScore    = eventsOfMatch?.Where(x => (x.EventName?.ToUpper() == "GOAL" || x.EventName?.ToUpper() == "PENALTYSCORED" || x.EventName?.ToUpper() == "OWNGOAL") && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count();
                selectedMatch.AwayTeamScore    = eventsOfMatch?.Where(x => (x.EventName?.ToUpper() == "GOAL" || x.EventName?.ToUpper() == "PENALTYSCORED" || x.EventName?.ToUpper() == "OWNGOAL") && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count();
                selectedMatch.HomeTeamOnTarget = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "ONTARGET" && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count();
                selectedMatch.AwayTeamOnTarget = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "ONTARGET" && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count();
                selectedMatch.HomeTeamCorner   = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "CORNER" && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count();
                selectedMatch.AwayTeamCorner   = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "CORNER" && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count();

                var playersOfMatch = _dystirDBContext.PlayersOfMatches.Where(x => x.MatchId == selectedMatch.MatchID)?.ToList();
                foreach (PlayersOfMatches playerOfMatch in playersOfMatch ?? new List <PlayersOfMatches>())
                {
                    playerOfMatch.Goal       = 0;
                    playerOfMatch.OwnGoal    = 0;
                    playerOfMatch.YellowCard = 0;
                    playerOfMatch.RedCard    = 0;
                    playerOfMatch.SubIn      = -1;
                    playerOfMatch.SubOut     = -1;
                    playerOfMatch.Assist     = 0;
                }
                foreach (EventsOfMatches eventMatch in eventsOfMatch ?? new List <EventsOfMatches>())
                {
                    PlayersOfMatches playerOfMatch = playersOfMatch?.FirstOrDefault(x => x.PlayerOfMatchId == eventMatch.MainPlayerOfMatchId);
                    if (playerOfMatch != null)
                    {
                        PlayersOfMatchValuesFromEvent(playerOfMatch, eventMatch);
                    }
                }
                _dystirDBContext.SaveChanges();
            }
        }
コード例 #3
0
        private Players SetNewPlayer(PlayersOfMatches playersOfMatches)
        {
            Players newPlayer = new Players()
            {
                FirstName = playersOfMatches.FirstName,
                LastName  = playersOfMatches.Lastname,
                Team      = playersOfMatches.TeamName,
                TeamId    = playersOfMatches.TeamId
            };

            _dystirDBContext.Players.Add(newPlayer);
            _dystirDBContext.SaveChanges();
            return(newPlayer);
        }
コード例 #4
0
        public IActionResult DeletePlayersOfMatches(int id)
        {
            PlayersOfMatches playersOfMatches = _dystirDBContext.PlayersOfMatches.Find(id);

            if (playersOfMatches == null)
            {
                return(NotFound());
            }

            _dystirDBContext.PlayersOfMatches.Remove(playersOfMatches);
            _dystirDBContext.SaveChanges();
            Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == playersOfMatches.MatchId);

            HubSend(match);
            return(Ok(playersOfMatches));
        }
コード例 #5
0
        public IActionResult PostPlayersOfMatches(PlayersOfMatches playersOfMatches)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (playersOfMatches.PlayerId == null)
            {
                Players newPlayer = SetNewPlayer(playersOfMatches);

                playersOfMatches.PlayerId = newPlayer.PlayerId;
            }
            _dystirDBContext.PlayersOfMatches.Add(playersOfMatches);
            _dystirDBContext.SaveChanges();
            Matches match = _dystirDBContext.Matches.FirstOrDefault(x => x.MatchID == playersOfMatches.MatchId);

            HubSend(match);

            return(CreatedAtRoute("DefaultApi", new { id = playersOfMatches.PlayerOfMatchId }, playersOfMatches));
        }
コード例 #6
0
        private void PlayersOfMatchValuesFromEvent(PlayersOfMatches playerOfMatch, EventsOfMatches eventMatch)
        {
            try
            {
                switch (eventMatch?.EventName?.ToUpper())
                {
                case "GOAL":
                case "PENALTYSCORED":
                    playerOfMatch.Goal += 1;
                    break;

                case "OWNGOAL":
                    playerOfMatch.OwnGoal += 1;
                    break;

                case "YELLOW":
                    playerOfMatch.YellowCard += 1;
                    break;

                case "RED":
                    playerOfMatch.RedCard += 1;
                    break;

                case "ASSIST":
                    playerOfMatch.Assist += 1;
                    break;

                case "SUBSTITUTION":
                    int    subsMinute  = 0;
                    string eventMinute = eventMatch.EventMinute.TrimStart('0').Replace("'", "");
                    if (string.IsNullOrWhiteSpace(eventMinute))
                    {
                        eventMinute = "0";
                    }
                    switch (eventMatch.EventPeriodId)
                    {
                    case 3:
                        eventMinute = "45";
                        break;

                    case 5:
                        eventMinute = "90";
                        break;

                    case 7:
                        eventMinute = "105";
                        break;

                    case 9:
                    case 10:
                    case 12:
                    case 13:
                    case 14:
                    case 20:
                    case 30:
                        eventMinute = "120";
                        break;
                    }
                    int index = eventMinute.IndexOf('+');
                    if (index > 0)
                    {
                        subsMinute = Convert.ToInt32(eventMinute.Substring(0, index));
                    }
                    else
                    {
                        subsMinute = Convert.ToInt32(eventMinute);
                    }
                    playerOfMatch.SubOut = subsMinute;
                    PlayersOfMatches secondPlayersOfMatches = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventMatch.SecondPlayerOfMatchId);
                    if (secondPlayersOfMatches != null)
                    {
                        secondPlayersOfMatches.SubIn = subsMinute;
                    }
                    break;
                }
            }
            catch
            {
            };
        }
コード例 #7
0
        private void CreateTextOfEvent(EventsOfMatches eventsOfMatches)
        {
            PlayersOfMatches playersOfMatches   = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventsOfMatches.MainPlayerOfMatchId);
            string           mainPlayerFullName = (playersOfMatches?.FirstName?.Trim() + " " + playersOfMatches?.Lastname?.Trim())?.Trim();

            switch (eventsOfMatches?.EventName?.ToUpper())
            {
            case "GOAL":
                eventsOfMatches.EventText = "MÁL til " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Málskjútti " + mainPlayerFullName + ".");
                break;

            case "OWNGOAL":
                eventsOfMatches.EventText = "MÁL til " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Sjálvmál " + mainPlayerFullName + ".");
                break;

            case "YELLOW":
                eventsOfMatches.EventText = "GULKORT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "RED":
                eventsOfMatches.EventText = "REYTTKORT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "CORNER":
                eventsOfMatches.EventText = "HORNASPARK til " + eventsOfMatches.EventTeam + ".";
                break;

            case "ONTARGET":
                eventsOfMatches.EventText = "ROYND Á MÁL. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd á mál.";
                break;

            case "OFFTARGET":
                eventsOfMatches.EventText = "ROYND FRAMVIÐ MÁL. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd framvið mál.";
                break;

            case "BLOCKEDSHOT":
                eventsOfMatches.EventText = "BLOKERA SKOT. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " roynd er blokerað.";
                break;

            case "BIGCHANCE":
                eventsOfMatches.EventText = "STÓRUR MØGULEIKI. " + eventsOfMatches.EventTeam + " leikari" + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : " " + mainPlayerFullName) + " stórur mál møguleiki.";
                break;

            case "SUBSTITUTION":
                PlayersOfMatches secondPlayersOfMatches = _dystirDBContext.PlayersOfMatches.FirstOrDefault(x => x.PlayerOfMatchId == eventsOfMatches.SecondPlayerOfMatchId);
                string           secongPlayerFullName   = (secondPlayersOfMatches?.FirstName?.Trim() + " " + secondPlayersOfMatches?.Lastname?.Trim())?.Trim();
                eventsOfMatches.EventText = "ÚTSKIFTING " + eventsOfMatches.EventTeam + ". " + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "" : "Leikari " + mainPlayerFullName + " út. ") + (string.IsNullOrWhiteSpace(secongPlayerFullName) ? "" : "Leikari " + secongPlayerFullName + " inn.");
                break;

            case "ASSIST":
                eventsOfMatches.EventText = "UPPLEGG " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "PENALTY":
                eventsOfMatches.EventText = "BROTSSPARK til " + eventsOfMatches.EventTeam + ".";
                break;

            case "PENALTYSCORED":
                eventsOfMatches.EventText = "BROTSSPARK SKORA " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "PENALTYMISSED":
                eventsOfMatches.EventText = "BROTSSPARK BRENT " + eventsOfMatches.EventTeam + (string.IsNullOrWhiteSpace(mainPlayerFullName) ? "." : " leikari " + mainPlayerFullName + ".");
                break;

            case "COMMENTARY":
                eventsOfMatches.EventText = "HENDINGAR: " + eventsOfMatches.EventText;
                break;
            }
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        public IQueryable <PlayersOfMatches> GetPlayersOfMatchByTeam([FromQuery] string hometeamname, [FromQuery] string awayteamname, [FromQuery] int competitionid, [FromQuery] int selectedmatchid)
        {
            hometeamname = hometeamname != null?hometeamname.Trim() : string.Empty;

            awayteamname = awayteamname != null?awayteamname.Trim() : string.Empty;

            Matches selectedMatch = _dystirDBContext.Matches?.FirstOrDefault(x => x.MatchID == selectedmatchid);

            if (selectedMatch == null)
            {
                return(Enumerable.Empty <PlayersOfMatches>().AsQueryable());
            }
            selectedMatch.MatchTypeName = selectedMatch.MatchTypeName != null?selectedMatch.MatchTypeName.Trim() : string.Empty;

            var lastmatches = _dystirDBContext.Matches?.Where(x => x.MatchTypeName.ToLower() == selectedMatch.MatchTypeName.ToLower() &&
                                                              (x.StatusID == 12 || x.StatusID == 13) &&
                                                              (x.HomeTeam.ToLower() == hometeamname.ToLower() ||
                                                               x.AwayTeam.ToLower() == hometeamname.ToLower() ||
                                                               x.HomeTeam.ToLower() == awayteamname.ToLower() ||
                                                               x.AwayTeam.ToLower() == awayteamname.ToLower())).OrderByDescending(x => x.Time);

            int?hometeamLastMatchID = lastmatches?.FirstOrDefault(x => x.HomeTeam.ToLower() == hometeamname.ToLower() ||
                                                                  x.AwayTeam.ToLower() == hometeamname.ToLower())?.MatchID;

            int?awayteamLastMatchID = lastmatches?.FirstOrDefault(x => x.HomeTeam.ToLower() == awayteamname.ToLower() ||
                                                                  x.AwayTeam.ToLower() == awayteamname.ToLower())?.MatchID;

            var playersByMatchID = GetPlayersOfMatchesByMatchID(selectedmatchid).ToList();

            var homePlayersFromLastMatch = hometeamLastMatchID != null?
                                           GetPlayersOfMatchesByMatchID((int)hometeamLastMatchID).Where(x => x.TeamName == hometeamname).ToList() : new List <PlayersOfMatches>();

            var awayPlayersFromLastMatch = awayteamLastMatchID != null?
                                           GetPlayersOfMatchesByMatchID((int)awayteamLastMatchID).Where(x => x.TeamName == awayteamname).ToList() : new List <PlayersOfMatches>();

            homePlayersFromLastMatch.AddRange(awayPlayersFromLastMatch);

            var playersFromLastMatch = homePlayersFromLastMatch?.Where(x => !playersByMatchID.Any(p => p.PlayerId == x.PlayerId));

            foreach (PlayersOfMatches player in playersFromLastMatch ?? new List <PlayersOfMatches>())
            {
                PlayersOfMatches newPlayerOfMatch = new PlayersOfMatches()
                {
                    MatchId       = selectedmatchid,
                    FirstName     = player.FirstName,
                    Lastname      = player.Lastname,
                    TeamName      = player.TeamName,
                    TeamId        = player.TeamId,
                    Number        = player.Number,
                    PlayerId      = player.PlayerId,
                    Position      = player.Position,
                    Captain       = player.Captain,
                    MatchTypeName = player.MatchTypeName,
                    MatchTypeId   = player.MatchTypeId,
                    PlayingStatus = 0,
                    Goal          = 0,
                    OwnGoal       = 0,
                    SubIn         = -1,
                    SubOut        = -1,
                    RedCard       = 0,
                    YellowCard    = 0
                };
                if (newPlayerOfMatch.PlayerId != null)
                {
                    _dystirDBContext.PlayersOfMatches.Add(newPlayerOfMatch);
                }
            }
            try
            {
                _dystirDBContext.SaveChanges();
            }
            catch {}

            var allPlayersList     = GetPlayersOfMatchesByMatchID(selectedmatchid)?.ToList();
            var playersListByTeams = _dystirDBContext.Players?
                                     .Where(x => x.Team.ToLower() == hometeamname.ToLower() ||
                                            x.Team.ToLower() == awayteamname.ToLower()).ToList();

            foreach (Players player in playersListByTeams ?? new List <Players>())
            {
                PlayersOfMatches playerOfMatches = new PlayersOfMatches()
                {
                    FirstName     = player.FirstName,
                    Lastname      = player.LastName,
                    PlayingStatus = 3,
                    PlayerId      = player.PlayerId,
                    MatchId       = selectedmatchid,
                    MatchTypeId   = competitionid,
                    TeamId        = player.TeamId,
                    TeamName      = player.Team
                };
                if (playerOfMatches.PlayerId != null && !allPlayersList.Any(pm => pm.PlayerId == playerOfMatches.PlayerId))
                {
                    allPlayersList.Add(playerOfMatches);
                }
                else
                {
                    string name = player.FirstName + " " + player.LastName;
                }
            }
            return(SortedPlayersOfMatchList(allPlayersList.AsQueryable()));
        }
コード例 #10
0
        internal CompetitionStatistic GetStatistics(ObservableCollection <Matches> allMatches, string competititionName, ObservableCollection <PlayersOfMatches> playersList)
        {
            CompetitionStatistic competitionStatistic = new CompetitionStatistic();

            try
            {
                competitionStatistic.CompetitionName = competititionName;
                competitionStatistic.TeamStatistics  = new List <TeamStatistic>();
                var matches = allMatches?.Where(x => x.MatchTypeName == competititionName && (x.RoundID < 1000));
                //&& (string.Equals(x.HomeTeam, team.TeamName, StringComparison.OrdinalIgnoreCase)
                //|| string.Equals(x.AwayTeam, team.TeamName, StringComparison.OrdinalIgnoreCase)));
                foreach (Matches match in matches)
                {
                    var players = playersList?.Where(p => p.MatchId == match.MatchID);
                    //HOME TEAM STATISTICS
                    bool          isNewHomeTeamStatistics = false;
                    TeamStatistic homeTeamFullStatistic   = new TeamStatistic();
                    if (competitionStatistic.TeamStatistics.Any(x => x.TeamName == match.HomeTeam))
                    {
                        homeTeamFullStatistic = competitionStatistic.TeamStatistics.FirstOrDefault(x => x.TeamName == match.HomeTeam);
                    }
                    else
                    {
                        isNewHomeTeamStatistics        = true;
                        homeTeamFullStatistic.TeamName = match.HomeTeam;
                    }
                    homeTeamFullStatistic.Goal     += match.HomeTeamScore ?? 0;
                    homeTeamFullStatistic.Corner   += match.HomeTeamCorner ?? 0;
                    homeTeamFullStatistic.OnTarget += match.HomeTeamOnTarget ?? 0 + match.HomeTeamScore ?? 0;
                    competitionStatistic.GoalPlayers.AddRange(players.Where(p => p.TeamName == match.HomeTeam && p.Goal > 0));
                    competitionStatistic.AssistPlayers.AddRange(players.Where(p => p.TeamName == match.HomeTeam && p.Assist > 0));
                    if (isNewHomeTeamStatistics)
                    {
                        competitionStatistic.TeamStatistics.Add(homeTeamFullStatistic);
                    }

                    //AWAY TEAM STATISTICS
                    bool          isNewAwayTeamStatistics = false;
                    TeamStatistic awayTeamFullStatistic   = new TeamStatistic();
                    if (competitionStatistic.TeamStatistics.Any(x => x.TeamName == match.AwayTeam))
                    {
                        awayTeamFullStatistic = competitionStatistic.TeamStatistics.FirstOrDefault(x => x.TeamName == match.AwayTeam);
                    }
                    else
                    {
                        isNewAwayTeamStatistics        = true;
                        awayTeamFullStatistic.TeamName = match.AwayTeam;
                    }
                    awayTeamFullStatistic.Goal     += match.AwayTeamScore ?? 0;
                    awayTeamFullStatistic.Corner   += match.AwayTeamCorner ?? 0;
                    awayTeamFullStatistic.OnTarget += match.AwayTeamOnTarget ?? 0 + match.AwayTeamScore ?? 0;
                    competitionStatistic.GoalPlayers.AddRange(players.Where(p => p.TeamName == match.AwayTeam && p.Goal > 0));
                    competitionStatistic.AssistPlayers.AddRange(players.Where(p => p.TeamName == match.AwayTeam && p.Assist > 0));
                    if (isNewAwayTeamStatistics)
                    {
                        competitionStatistic.TeamStatistics.Add(awayTeamFullStatistic);
                    }
                }

                var playersGoalGroup = competitionStatistic.GoalPlayers.GroupBy(x => x.FirstName);
                competitionStatistic.GoalPlayers = new List <PlayersOfMatches>();
                foreach (var playerGroup in playersGoalGroup)
                {
                    PlayersOfMatches newPlayers = new PlayersOfMatches()
                    {
                        FirstName = playerGroup.FirstOrDefault().FirstName,
                        TeamName  = playerGroup.LastOrDefault().TeamName,
                        Goal      = 0
                    };

                    foreach (PlayersOfMatches playerOfMatch in playerGroup)
                    {
                        newPlayers.Goal += playerOfMatch.Goal;
                    }
                    competitionStatistic.GoalPlayers.Add(newPlayers);
                }
                competitionStatistic.GoalPlayers = competitionStatistic.GoalPlayers.OrderByDescending(x => x.Goal).ThenBy(x => x.TeamName).ThenBy(x => x.FirstName).ToList();

                var playersAssistGroup = competitionStatistic.AssistPlayers.GroupBy(x => x.FirstName);
                competitionStatistic.AssistPlayers = new List <PlayersOfMatches>();
                foreach (var playerGroup in playersAssistGroup)
                {
                    PlayersOfMatches newPlayers = new PlayersOfMatches()
                    {
                        FirstName = playerGroup.FirstOrDefault().FirstName,
                        TeamName  = playerGroup.LastOrDefault().TeamName,
                        Assist    = 0
                    };
                    foreach (PlayersOfMatches playerOfMatch in playerGroup)
                    {
                        newPlayers.Assist += playerOfMatch.Assist;
                    }
                    competitionStatistic.AssistPlayers.Add(newPlayers);
                }
                competitionStatistic.AssistPlayers = competitionStatistic.AssistPlayers.OrderByDescending(x => x.Assist).ThenBy(x => x.TeamName).ThenBy(x => x.FirstName).ToList();
            }
            catch (Exception ex)
            {
                var exception = ex.Message;
            }
            return(competitionStatistic);
        }