static void DisplayHighScores() { //clear the console Console.Clear(); //Write the High Score Text Console.WriteLine("Guess That Number High Scores"); Console.WriteLine("-----------------------------"); //create a new connection to the database DustinEntities db = new DustinEntities(); //get the high score list List <HighScore> highScoreList = db.HighScores .Where(x => x.Game == "Guess That Number") .OrderBy(x => x.Score).Take(10) .ToList(); foreach (HighScore highScore in highScoreList) { Console.WriteLine("{0}. {1} - {2} on {3}", highScoreList.IndexOf(highScore) + 1, highScore.Name, highScore.Score, highScore.DateCreated.Value.ToShortDateString()); } Console.WriteLine("\n\n\n"); }
static void AddHighScore(int playerScore) { //get the player name for the high scores Console.WriteLine("Your name:"); string playerName = Console.ReadLine(); //create a gateway to the database DustinEntities db = new DustinEntities(); //create a new high score object, // fill it with our user's data HighScore newHighScore = new HighScore(); newHighScore.DateCreated = DateTime.Now; newHighScore.Game = "Guess That Number"; newHighScore.Name = playerName; newHighScore.Score = playerScore; //add it to the database db.HighScores.Add(newHighScore); //save our changes db.SaveChanges(); }