示例#1
0
        public async Task <bool> SaveRecord()
        {
            bool bOK = true;

            try
            {
                using (var db = new DbContextScores())
                {
                    db.Scores.Add(this);
                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error($"SaveRecord exception, {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }
示例#2
0
        // load all score records
        public static bool LoadAllRecords(out List <Score> results)
        {
            bool bOK = true;

            results = new List <Score>();
            try
            {
                using (var db = new DbContextScores())
                {
                    db.Database.EnsureCreated();
                    results = db.Scores.OrderByDescending(item => item.Points).ToList();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error($"LoadAllRecords exception, {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }
示例#3
0
        // get new score rank
        public static bool GetScoreRank(int score, out int ranking)
        {
            bool bOK = true;

            ranking = 1;
            try
            {
                using (var db = new DbContextScores())
                {
                    db.Database.EnsureCreated();
                    var count = db.Scores.Where(item => item.Points > score).Count();
                    ranking = count + 1;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error($"GetScoreRank exception, {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }
示例#4
0
        // delete all scores
        internal static async Task <bool> DeleteAllRecords()
        {
            bool bOK = true;

            try
            {
                using (var db = new DbContextScores())
                {
                    foreach (var score in db.Scores)
                    {
                        db.Scores.Remove(score);
                    }
                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error($"DeleteAllRecords exception, {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }