diff --git a/UserService/Extensions/JSInteropExtensions.cs b/UserService/Extensions/JSInteropExtensions.cs new file mode 100644 index 0000000..d9d91e8 --- /dev/null +++ b/UserService/Extensions/JSInteropExtensions.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using Microsoft.JSInterop; + +public static class JSInteropExtensions +{ + public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeAsync("confirm", message); + } + + public static ValueTask Alert(this IJSRuntime jsRuntime, string message) + { + return jsRuntime.InvokeVoidAsync("alert", message); + } +} \ No newline at end of file diff --git a/UserService/Pages/SecurityGroups.razor.cs b/UserService/Pages/SecurityGroups.razor.cs index 66e1390..27b4a18 100644 --- a/UserService/Pages/SecurityGroups.razor.cs +++ b/UserService/Pages/SecurityGroups.razor.cs @@ -45,8 +45,7 @@ namespace UserService.Pages protected override async Task RowDeletingCallback(CancellableRowChange arg) { if (arg == null) throw new ArgumentNullException(nameof(arg)); - var confirmed = await JsRuntime.InvokeAsync("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; } diff --git a/UserService/Pages/Users.razor.cs b/UserService/Pages/Users.razor.cs index f13faf1..ebfe327 100644 --- a/UserService/Pages/Users.razor.cs +++ b/UserService/Pages/Users.razor.cs @@ -31,7 +31,7 @@ namespace UserService.Pages Members ?? Enumerable.Empty()); 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 arg) { if (arg == null) throw new ArgumentNullException(nameof(arg)); - var confirmed = await JsRuntime.InvokeAsync("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; }