private async void EditPlayer(Player playerToEdit) { try { TextEntryDialogViewModel dialogViewModel = new TextEntryDialogViewModel("Edit Player", string.Format("Enter a new name for {0}", playerToEdit.name), playerToEdit.name); ContentDialogResult result = await _dialogService.ShowContentDialogAsync(dialogViewModel); if (result == ContentDialogResult.Primary) { if (!_playerRepo.PlayerExists(dialogViewModel.input)) { playerToEdit.name = dialogViewModel.input; _playerRepo.EditPlayer(playerToEdit); } else { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Player Already Exists", "A player with that name already exists in the database. Please choose a new name")); } } } catch (SQLiteException) { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Error", "Something went wrong, please try again")); } }
private async void CreatePlayer() { try { TextEntryDialogViewModel dialogViewModel = new TextEntryDialogViewModel("Create New Player", "Enter a name for the new player", "Player Name"); ContentDialogResult result = await _dialogService.ShowContentDialogAsync(dialogViewModel); if (result == ContentDialogResult.Primary) { if (!_playerRepo.PlayerExists(dialogViewModel.input)) { _playerRepo.AddPlayer(new Player { name = dialogViewModel.input }); IEnumerable <Player> newAllPlayers; newAllPlayers = _playerRepo.GetAllPlayers(); foreach (Player player in newAllPlayers) { if (allPlayers.SingleOrDefault(p => p.id == player.id) == null) { player.selectedToPlay = true; allPlayers.Add(player); } } } else { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Player Already Exists", "A player with that name already exists in the database. Please choose a new name")); } } } catch (SQLiteException) { await _dialogService.ShowContentDialogAsync(new MessageDialogViewModel("Error", "Something went wrong, please try again")); } }