private void LoadTournament() { Log.Debug("Loading tournament..."); TournamentRepository tournamentRepository = new TournamentRepository(); if(SelectedFile != null) { Tournament tournament = tournamentRepository.LoadTournamentFromXML(SelectedFile.RecentFile.FullName); var tournamentViewModel = new TournamentViewModel(tournament, SelectedFile.RecentFile.FullName); Messenger.Default.Send(new NotificationMessage<ViewModelBase>(this, tournamentViewModel, "TournamentViewModel")); } else { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Open XML bestand"; openFileDialog.DefaultExt = ".xml"; openFileDialog.Filter = "XML documents (.xml)|*.xml"; openFileDialog.CheckFileExists = true; openFileDialog.CheckPathExists = true; if (openFileDialog.ShowDialog() == true) { Tournament tournament = tournamentRepository.LoadTournamentFromXML(openFileDialog.FileName); var tournamentViewModel = new TournamentViewModel(tournament); Messenger.Default.Send(new NotificationMessage<ViewModelBase>(this, tournamentViewModel, "TournamentViewModel")); } } //Making it null again in case we want to access the method out of the first window (for example starting a new tournament while in the tournamentViewModel) //If we don't do this, we always get in the first if and it will always open the tournament that was originally selected. SelectedFile = null; }
//TODO Repositories solution: We shouldn't create them each time we need them. Can we make them accesible everywhere somehow? i.e static class controller? /// <summary> /// This method is responsible for saving a tournament to a certain path. /// TODO Should we insert a recent file here or automaticly when we save a tournament, so in the tournament repository. /// </summary> /// <param name="uri"></param> private void Save(string uri) { Log.Debug(uri); RecentFileRepository recentFileRepository = new RecentFileRepository(); TournamentRepository tournamentRepository = new TournamentRepository(); tournamentRepository.SaveTournamentAsXML(CurrentTournament, uri); recentFileRepository.InsertFile(uri); }