static void DisplayHighScores() { Console.Clear(); Console.WriteLine("Guess That Number High Scores\n================================================="); HighScoresEntities db = new HighScoresEntities(); List<HighScore> HighScores = db.HighScores.Where(x => x.Game == "Guess That Number").OrderBy(x => x.Score).Take(10).ToList(); foreach (var item in HighScores) { Console.WriteLine("{0}. {1} - {2}", HighScores.IndexOf(item)+1, item.Name, item.Score); } }
static void AddHighScore(int playerScore) { Console.WriteLine("What is your name?"); string playerName = Console.ReadLine(); //create a gateway to the database HighScoresEntities db = new HighScoresEntities(); HighScore thisScore = new HighScore(); thisScore.Time = DateTime.Now; thisScore.Game = "Guess That Number"; thisScore.Name = playerName; thisScore.Score = playerScore; db.HighScores.Add(thisScore); db.SaveChanges(); }