/**
         * Create teamPlayers attached to the league
         */
        private async Task <League> createLeagueWithTeamPlayers(League leagueInCreation, int ruleSetId)
        {
            List <TeamPlayer> teamPlayersCreated = new List <TeamPlayer>();

            // for each team players, we see in database if it already exists, if so, we add it to the leage without creating it before
            foreach (TeamPlayer tp in leagueInCreation.TeamPlayers)
            {
                TeamPlayer dbTeamPlayer = this.db.TeamPlayers.Where(tpWhere => tpWhere.PlayerId == tp.PlayerId &&
                                                                    tpWhere.TeamId == tp.TeamId).FirstOrDefault();
                if (dbTeamPlayer != null)
                {
                    teamPlayersCreated.Add(dbTeamPlayer);
                }
                else
                {
                    // Add the team players to the season
                    teamPlayersCreated.Add(tp);
                }
            }
            leagueInCreation.TeamPlayers = teamPlayersCreated;

            // we update the league then
            leagueInCreation = this.db.Leagues.Add(leagueInCreation);
            await db.SaveChangesAsync();

            // Then we create the matches and the scores
            leagueInCreation.Matches = await ruleSetRepo.createMatchAndScore(leagueInCreation.TeamPlayers, ruleSetId);

            db.Entry(leagueInCreation).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(leagueInCreation);
        }
        // Add one TeamPlayer
        public async Task <TeamPlayer> Add(TeamPlayer item)
        {
            db.TeamPlayers.Add(item);
            await db.SaveChangesAsync();

            return(item);
        }
        // Update a TeamPlayer by its ID
        public async Task <bool> Update(int id, TeamPlayer item)
        {
            if (item == null)
            {
                return(false);
            }
            item.Id = id;

            db.Entry(item).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(true);
        }
        // remove a TeamPlayer by its id
        public async Task <bool> Remove(int id)
        {
            TeamPlayer teamPlayer = db.TeamPlayers.Find(id);

            if (teamPlayer == null)
            {
                return(false);
            }

            db.TeamPlayers.Remove(teamPlayer);
            await db.SaveChangesAsync();

            return(true);
        }
        private static Match createMatch(TeamPlayer homeTeam, TeamPlayer awayTeam)
        {
            //add match & score
            Match match = new Match {
            };

            match.Played = false;

            var scoreHomePlayer1 = new Score {
                Location = Location.Home, TeamPlayerId = homeTeam.Id
            };
            var scoreAwayPlayer2 = new Score {
                Location = Location.Away, TeamPlayerId = awayTeam.Id
            };

            match.Scores = new List <Score> {
                scoreHomePlayer1, scoreAwayPlayer2
            };
            return(match);
        }