private static async Task <SportaMatchExcelCreator> CreateExcelCreator(int matchId, TtcDbContext dbContext)
        {
            int currentSeason = dbContext.CurrentSeason;
            var activePlayers = await dbContext.Players
                                .Where(x => x.Gestopt == null)
                                .Where(x => x.ClubIdSporta.HasValue)
                                .ToArrayAsync();

            var match = await dbContext.Matches
                        .Include(x => x.HomeTeam)
                        .Include(x => x.AwayTeam)
                        .Include(x => x.Players)
                        .SingleAsync(x => x.Id == matchId);

            var teams = await dbContext.Teams
                        .Include(x => x.Opponents.Select(o => o.Club))
                        .Where(x => x.Year == currentSeason)
                        .Where(x => x.Competition == Competition.Sporta.ToString())
                        .ToArrayAsync();

            var frenoy          = new FrenoyPlayersApi(dbContext, Competition.Sporta);
            var theirClubId     = match.AwayTeamId.HasValue ? match.HomeClubId : match.AwayClubId;
            var opponentPlayers = await frenoy.GetPlayers(theirClubId);

            var exceller = new SportaMatchExcelCreator(dbContext, match, activePlayers, teams, opponentPlayers);

            return(exceller);
        }
        public async Task FrenoySync()
        {
            using (var context = new TtcDbContext())
            {
                var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl);
                await vttlPlayers.StopAllPlayers(false);

                await vttlPlayers.SyncPlayers();

                var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta);
                await sportaPlayers.SyncPlayers();
            }
        }
        /// <summary>
        /// Adds the matches and syncs the players for the new season
        /// </summary>
        /// <returns>The new season year</returns>
        public static async Task <int> Seed(TtcDbContext context, bool clearMatches)
        {
            // TODO: Season 2020: Add GetOpponentMatches to initial seed (remove from MatchService)

            //if (clearMatches)
            //{
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchplayer");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchgame");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchcomment");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matches");
            //}

            //int newYear = context.CurrentFrenoySeason + 1;
            int newYear       = DateTime.Today.Year;
            int newFrenoyYear = newYear - 2000 + 1;

            if (DateTime.Today.Month < 7)
            {
                throw new Exception($"Starting new season {newYear}? That doesn't seem right?");
            }
            if (!context.Matches.Any(x => x.FrenoySeason == newFrenoyYear))
            {
                // VTTL
                var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl);
                await vttlPlayers.StopAllPlayers(true);

                await vttlPlayers.SyncPlayers();

                var vttl = new FrenoyMatchesApi(context, Competition.Vttl);
                await vttl.SyncTeamsAndMatches();


                // Sporta
                var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta);
                await sportaPlayers.StopAllPlayers(true);

                await sportaPlayers.SyncPlayers();

                var sporta = new FrenoyMatchesApi(context, Competition.Sporta);
                await sporta.SyncTeamsAndMatches();
            }

            //CreateSystemUser(context);

            return(newYear);
        }