static void DisplayHighScores() { Console.Clear(); Console.WriteLine("Dragon Slayer High Scores"); Console.WriteLine("-----------------------------"); KevinEntities db = new KevinEntities(); List<HighScore> highScoreList = db.HighScores.Where(x => x.Game == "Dragon Slayer").OrderBy(x => x.Score).Take(10).ToList(); foreach (HighScore i in highScoreList) { Console.WriteLine("{0}. {1} - {2} - {3}", highScoreList.IndexOf(i) + 1, i.Name, i.Score, i.DateCreated.Value.ToShortDateString()); } }
static void AddHighScore(int playerScore) { Console.WriteLine("Add your name to the high score list: "); string playerName = Console.ReadLine(); //Create a gateway to the database KevinEntities db = new KevinEntities(); //Create new high score object HighScore newHighScore = new HighScore(); newHighScore.DateCreated = DateTime.Now; newHighScore.Game = "Dragon Slayer"; newHighScore.Name = playerName; newHighScore.Score = playerScore; //Add it to the database db.HighScores.Add(newHighScore); //Save changes to db db.SaveChanges(); }