// Constructor public MainWindowViewModel() { _dataContext = new PuttingLeagueDb(); try { GetDefaultPointValues(); GetPlayers(); } catch (Exception ex) { MessageBox.Show("Database could not be opened. If the problem persists, try recreating the database.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void recreateDatabase() { DialogResult result = MessageBox.Show("Recreating the database will delete all data in current database. Do you wish to continue?", "Recreate Database", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; _dataContext.Database.Delete(); _dataContext = new PuttingLeagueDb(); GetDefaultPointValues(); GetPlayers(); Mouse.OverrideCursor = null; } }
// Constructor public EditRoundScoresViewModel(PuttingLeagueDb db, int gameID, int teamID, int currentRound) { _dataManager = db; _gameID = gameID; _teamID = teamID; _currentRound = currentRound; // Get the game Game game = _dataManager.Games.SingleOrDefault(e => e.GameID == _gameID); // Get the teams foreach (Team team in game.Teams) { _teams.Add(team); } // Get all of the round scores foreach (RoundScore rs in game.RoundScores) { _allRoundScores.Add(rs); } // Get the round options for (int i = 1; i <= _currentRound; i++) { _roundOptions.Add(i); } // Get the point options _pointOptions.Add(0); foreach (PointValue pv in game.PointValues) { _pointOptions.Add(pv.Points); } // Set the entity state to detached so changes aren't automatically saved foreach (RoundScore rs in _allRoundScores) { _dataManager.Entry(rs).State = EntityState.Detached; } SelectedTeam = _teams.SingleOrDefault(e => e.TeamID == teamID); DialogResult = false; }