Example #1
0
        public static async Task <bool> SaveRecords(List <Word> words)
        {
            bool bOK = true;

            try
            {
                using (var db = new DbContextWords())
                {
                    await db.Words.AddRangeAsync(words);

                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"SaveRecords exception {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }
Example #2
0
        // Load all records with a difficulty filter.
        public static bool LoadRecords(Defines.GameDifficulty difficulty, out List <Word> results)
        {
            results = null;
            bool bOK = true;

            try
            {
                using (var db = new DbContextWords())
                {
                    db.Database.EnsureCreated();
                    results = (from item in db.Words
                               where item.WordDifficulty <= difficulty
                               orderby item ascending
                               select item).ToList();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"LoadRecords exception {ex.Message}");
                bOK = false;
            }
            return(bOK);
        }