예제 #1
0
         static void AddHighScore(int playerScore)
        {
            Console.WriteLine("Your Name: ");
            string playerName = Console.ReadLine();

            //create a gateway to the database
            MorganEntities db = new MorganEntities();
            
            //create a new highsccore object
            HighScore newHighScore =  new HighScore();

            newHighScore.DateCreated = DateTime.Now;
            newHighScore.Game = "Dragon Combat 2.0";
            newHighScore.Name = playerName;
            newHighScore.Score = playerScore;

            //add it to the database
            db.HighScores.Add(newHighScore);

            //save our changes
            db.SaveChanges();
        }
예제 #2
0
        //add the highscores to the database
        static void AddHighScore(int playerScore)
        {
            //get the name for the player
            Console.WriteLine("\n\nYour name:\n");
            string playerName = Console.ReadLine();

            //create a gateway to the database
            spDrewEntities db = new spDrewEntities();

            //create a new highscore object
            HighScore newHighscore = new HighScore();

            newHighscore.DateCreated = DateTime.Now;
            newHighscore.Game        = "Dragon Combat 2.0";
            newHighscore.Name        = playerName;
            newHighscore.Score       = playerScore;

            //add it to the database
            db.HighScores.Add(newHighscore);


            //always save changes, but only need to type this one time
            db.SaveChanges();
        }