Пример #1
0
 /// <summary>
 /// Save Results
 /// </summary>
 /// <param name="playerName">Player Name</param>
 /// <param name="score">Player score</param>
 public static void SaveResult(string playerName, int score)
 {
     using (UserScoreEntities db = new UserScoreEntities())
     {
         var newScore = new Score()
         {
             UserName = playerName, MyScore = score, DateAdded = DateTime.Now
         };
         db.Users.Add(newScore);
         db.SaveChanges();
     }
 }
Пример #2
0
        /// <summary>
        /// Get 10 top results
        /// </summary>
        /// <returns></returns>
        public static List <Score> GetTopResult()
        {
            using (UserScoreEntities db = new UserScoreEntities())
            {
                var resList = db.Users.OrderByDescending(x => x.MyScore).ToList();
                if (resList.Count > 10)
                {
                    resList = resList.Take(10).ToList();
                }
                else
                {
                    resList = resList.Take(resList.Count).ToList();
                }

                return(resList);
            }
        }