示例#1
0
        static void DisplayHighScores()
        {
            Console.Clear();
            Console.WriteLine("Trivia High Scores");
            Console.WriteLine("-----------------------------");

            KevinEntities db = new KevinEntities();
            List<HighScore> highScoreList = db.HighScores.Where(x => x.Game == "Trivia").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());
            }
        }
示例#2
-1
        static void AddHighScore(int playerScore)
        {
            Console.WriteLine("Add your name to high scores 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 = "Trivia";
            newHighScore.Name = playerName;
            newHighScore.Score = playerScore;

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

            //Save changes to db
            db.SaveChanges();
        }