protected void UpdateCurrentPuzzle() { using(PuzzleDataContext puzzleDb = new PuzzleDataContext(App.DbConnectionString)) { Puzzle nextPuzzle = puzzleDb.GetNextPuzzle(App.CurrentPuzzle.PuzzleId); if(nextPuzzle == null) { App.CurrentPuzzle = null; } else { App.CurrentPuzzle = nextPuzzle; } } }
/// <summary> /// Loads the current puzzle from the database, or the first puzzle if no current puzzle exists /// </summary> private void LoadCurrentPuzzle() { int currentPuzzleId = appSettings.GetCurrentPuzzleId(); using(PuzzleDataContext puzzleDb = new PuzzleDataContext(DbConnectionString)) { if (currentPuzzleId == int.MinValue) { CurrentPuzzle = puzzleDb.GetFirstPuzzle(); } else { CurrentPuzzle = puzzleDb.GetPuzzleById(currentPuzzleId); } } }
/// <summary> /// Checks that the puzzle database exists, throws an exception if it doesn't /// </summary> private void CheckDatabase() { PuzzleDataContext puzzleDb = new PuzzleDataContext(DbConnectionString); if(puzzleDb.DatabaseExists() == false) { // TODO : Add exception handling for entire application throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "Failed to locate database with given database string : {0}", DbConnectionString)); } }