public async Task DeleteGame(Game game) { var result = await ConfirmModal.ExecuteModalAsync(ModalService, new ConfirmModal.Input { Title = "Delete game", Message = "Really delete game? This cannot be undone", OkButtonCaption = "Delete game", CancelButtonCaption = "Cancel" }); if (result == ConfirmModal.Result.Ok) { foreach (var round in game.Rounds) { foreach (var playerRound in round.PlayerRounds) { foreach (var letter in playerRound.Letters) { DbContext.Remove(letter); } DbContext.Remove(playerRound); } DbContext.Remove(round); foreach (var gamePlayer in game.GamePlayers) { DbContext.Remove(gamePlayer); } } DbContext.Remove(game); await DbContext.SaveChangesAsync(); Games.RemoveAll(g => g.Game == game); } }
/// <summary> /// Displays the confirm modal and returns a <see cref="Task"/> whose result represents /// the closing of the modal. /// </summary> /// <param name="viewModel">The confirm modal view model.</param> /// <returns></returns> public Task ShowConfirmModal(ConfirmModalViewModel viewModel) { // The task that will be used to await the closing of the modal var modalClosedTaskCompletionSource = new TaskCompletionSource <bool>(); Task.Run(() => { // Run on the UI thread Application.Current.Dispatcher.Invoke(async() => { try { // Create the confirm modal var confirmModal = new ConfirmModal(); // Show it and wait for it to be dismissed await confirmModal.Show(viewModel); } finally { // Let the caller know that the modal has been closed modalClosedTaskCompletionSource.TrySetResult(true); } }); }); return(modalClosedTaskCompletionSource.Task); }
public ActionResult GetConfirmPartial(ConfirmModal data) { return(View(data)); }