//Display high scores from the data base static void DisplayHighScores() { //create a DB connection GuessThatNumberFinalFinal.JayaEntities db = new GuessThatNumberFinalFinal.JayaEntities(); List <GuessThatNumberFinalFinal.HighScore> highScoreList = db.HighScores.Where(x => x.Game == "Guess That Number").OrderByDescending(x => x.Score).Take(10).ToList(); foreach (var item in highScoreList) { Console.WriteLine(item.Name + " " + item.Score); } }
//Add Score to the data base static void AddScoreToDB() { Console.WriteLine("Enter your name"); string name = Console.ReadLine(); Console.Clear(); Console.WriteLine("Guess That Number High Scores"); Console.WriteLine("=============================="); GuessThatNumberFinalFinal.JayaEntities db = new GuessThatNumberFinalFinal.JayaEntities(); GuessThatNumberFinalFinal.HighScore cureentScore = new GuessThatNumberFinalFinal.HighScore(); cureentScore.Score = score; cureentScore.Name = name; cureentScore.Game = "Guess That Number"; cureentScore.DateCreated = DateTime.Now; //add to data base db.HighScores.Add(cureentScore); //commit to data base db.SaveChanges(); }