public void NewGame() { var view = new GameDetailView(Items, null); view.ShowDialog(); foreach (var item in Items) { if (!AllGames.Any(a => a.Month.Equals(item.Month) && a.Theme.Equals(item.Theme))) { AllGames.Add(item); } } Items = GetGameItems(Filter); }
public static GameInfo CreateGame(Player.PlayerInfo player) { GameInfo res = new GameInfo(); res.Creator = player; res.ID = (uint)(AllGames.Count + 0x5DC695); res.MID = (uint)(AllGames.Count + 0x1129DA20); res.isActive = true; res.Update = true; res.OtherPlayers = new List <Player.PlayerInfo>(); res.Attributes = new List <Attribut>(); res.GAMESETTING = 0; res.GAMESTATE = 0; AllGames.Add(res); return(res); }
public void Save() { var canClose = false; IsBusy = true; var bgWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; bgWorker.DoWork += (sender, args) => { try { AllGames = GameRepository.Get(null); if (SelectedGame == null && AllGames.Any(w => w.Month.Equals(Month) && w.Theme.Equals(Theme))) { MessageBox.Show($"Er bestaat reeds een wedstrijd met id {Month} - {Theme}.", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); IsBusy = false; return; } if (string.IsNullOrEmpty(Resolution)) { MessageBox.Show("Gelieve een resolutie in te geven.", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); IsBusy = false; return; } if (!MaxToUpload.HasValue) { MessageBox.Show("Gelieve een max in te geven.", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); IsBusy = false; return; } var gameToSave = SelectedGame != null ? AllGames.FirstOrDefault(w => w.Month.Equals(SelectedGame.Month) && w.Theme.Equals(SelectedGame.Theme)) : new GameItem(); if (gameToSave != null) { gameToSave.Club = OrganisationName; gameToSave.Month = Month; gameToSave.Theme = Theme; gameToSave.GameDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); gameToSave.Resolution = Resolution; gameToSave.MaxToUpload = MaxToUpload.Value; if (SelectedGame == null) { AllGames.Add(gameToSave); } } XmlFactory.WriteXml(FolderFactory.MemberFolder, "Games", AllGames); LogFactory.WriteToLog("De wedstrijd is met succes aangepast.", "GameDetailViewModel.Save", ActivityLogTypes.Success, App.ActivityLogFileName); IsBusy = false; MessageBox.Show("De gegevens zijn met succes bewaard.", "Informatie", MessageBoxButton.OK, MessageBoxImage.Information); canClose = true; } catch (Exception ex) { LogFactory.WriteToLog(ex.Message, "GameDetailViewModel.Save", ActivityLogTypes.Error, App.ActivityLogFileName); IsBusy = false; MessageBox.Show("Er is een fout opgetreden tijdens het bewaren van het lid.", "Fout", MessageBoxButton.OK, MessageBoxImage.Error); } }; bgWorker.RunWorkerCompleted += (sender, args) => CloseWindow(canClose); bgWorker.RunWorkerAsync(); }