コード例 #1
0
        static void Main(string[] args)
        {
            using (var context = new TtcDbContext())
            {
                try
                {
                    // This code can be triggered from the UI!
                    // Admin > Spelers > Frenoy Sync button (float: right)

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

                    // This code can be triggered by deploying a new migration
                    // --> No more at the moment with asyncy stuff see README.
                    var vttl = new FrenoyMatchesApi(context, Competition.Vttl);
                    vttl.SyncTeamsAndMatches();
                    var sporta = new FrenoyMatchesApi(context, Competition.Sporta);
                    sporta.SyncTeamsAndMatches();

                    //RandomizeMatchDatesForTestingPurposes(context);

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadKey();
                }
            }
        }
コード例 #2
0
        /// <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);
        }