예제 #1
0
        static void Main(string[] args)
        {
            var clubFlag      = false;
            var playersFlag   = false;
            var clearDatabase = false;
            var clubsPath     = "";
            var playersPath   = "";

            CheckArgs(args, ref clubFlag, ref playersFlag, ref clubsPath, ref playersPath, ref clearDatabase);
            var clubs   = new List <Club>();
            var players = new List <Player>();

            if (clubFlag && !string.IsNullOrWhiteSpace(clubsPath))
            {
                ReadClubs(ref clubs, clubsPath);
            }
            if (playersFlag && !string.IsNullOrWhiteSpace(playersPath))
            {
                ReadPlayers(ref players, playersPath, ref clubs);
            }
            #region InicializationDB
            using (var db_context = new HockeyContext())
            {
                if (clearDatabase)
                {
                    db_context.Database.ExecuteSqlCommand("DELETE FROM Player");
                    db_context.Database.ExecuteSqlCommand("DELETE FROM Club");
                }
                foreach (var club in clubs)
                {
                    db_context.Clubs.Add(club);
                }
                foreach (var player in players)
                {
                    db_context.Players.Add(player);
                }
                db_context.SaveChanges();
                foreach (var club in db_context.GetClubs())
                {
                    Console.WriteLine(club);
                }
                foreach (var player in db_context.GetPlayers())
                {
                    Console.WriteLine(player);
                }
            }
            Console.WriteLine("DB Loaded!");
            Console.ReadLine();
            #endregion
        }