added extension methods

This commit is contained in:
Holger Börchers 2020-08-26 21:27:27 +02:00
parent d2b4b1a0a0
commit 256bb47dfe
3 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1,15 @@
using System.Threading.Tasks;
using Microsoft.JSInterop;
public static class JSInteropExtensions
{
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeAsync<bool>("confirm", message);
}
public static ValueTask Alert(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeVoidAsync("alert", message);
}
}

View File

@ -45,8 +45,7 @@ namespace UserService.Pages
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
$"You are about to delete the security group {arg.Item.CommonName}. Are you sure?")
var confirmed = await JsRuntime.Confirm($"You are about to delete the security group {arg.Item.CommonName}. Are you sure?")
.ConfigureAwait(false);
arg.Cancel = !confirmed;
}

View File

@ -31,7 +31,7 @@ namespace UserService.Pages
Members ?? Enumerable.Empty<User>());
if (mailValidation == true && commonNameValidation == true) return;
await JsRuntime.InvokeVoidAsync("alert", "User could not be added").ConfigureAwait(false);
await JsRuntime.Alert("User could not be added").ConfigureAwait(false);
arg.Cancel = true;
}
@ -46,8 +46,7 @@ namespace UserService.Pages
protected override async Task RowDeletingCallback(CancellableRowChange<User> arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
var confirmed = await JsRuntime.Confirm($"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
arg.Cancel = !confirmed;
}