diff --git a/UserService/Extensions/JSInteropExtensions.cs b/UserService/Extensions/JSInteropExtensions.cs index d9d91e8..f40f05a 100644 --- a/UserService/Extensions/JSInteropExtensions.cs +++ b/UserService/Extensions/JSInteropExtensions.cs @@ -3,12 +3,12 @@ using Microsoft.JSInterop; public static class JSInteropExtensions { - public static ValueTask Confirm(this IJSRuntime jsRuntime, string message) + public static ValueTask ConfirmAsync(this IJSRuntime jsRuntime, string message) { return jsRuntime.InvokeAsync("confirm", message); } - public static ValueTask Alert(this IJSRuntime jsRuntime, string message) + public static ValueTask AlertAsync(this IJSRuntime jsRuntime, string message) { return jsRuntime.InvokeVoidAsync("alert", message); } diff --git a/UserService/Pages/SecurityGroups.razor b/UserService/Pages/SecurityGroups.razor index a33ae82..d261425 100644 --- a/UserService/Pages/SecurityGroups.razor +++ b/UserService/Pages/SecurityGroups.razor @@ -99,12 +99,49 @@ else - + + + + @@ + + + + + + + + + + + # + Common Name + + + + + + 1 + Mark + + + + 2 + Jacob + + + + 3 + Larry + + + +
+
diff --git a/UserService/Pages/SecurityGroups.razor.cs b/UserService/Pages/SecurityGroups.razor.cs index 27b4a18..ade6605 100644 --- a/UserService/Pages/SecurityGroups.razor.cs +++ b/UserService/Pages/SecurityGroups.razor.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Blazorise; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; using UserService.DatabaseLayer.Repositories; using UserService.Infrastructure.DataModels; @@ -22,7 +21,7 @@ namespace UserService.Pages // reference to the modal component protected Modal ModalRef { get; set; } = null!; - protected IEnumerable AvailableMembers { get; set; } + protected IEnumerable? AvailableMembers { get; set; } protected override async Task OnInitializedAsync() { @@ -45,7 +44,7 @@ namespace UserService.Pages protected override async Task RowDeletingCallback(CancellableRowChange arg) { if (arg == null) throw new ArgumentNullException(nameof(arg)); - var confirmed = await JsRuntime.Confirm($"You are about to delete the security group {arg.Item.CommonName}. Are you sure?") + var confirmed = await JsRuntime.ConfirmAsync($"You are about to delete the security group {arg.Item.CommonName}. Are you sure?") .ConfigureAwait(false); arg.Cancel = !confirmed; } @@ -65,20 +64,28 @@ namespace UserService.Pages protected async Task MySearchHandler(object arg) { - var addedMember = arg as Member; - if(addedMember is null) return; - var confirmed = await JsRuntime.InvokeAsync("confirm", addedMember?.CommonName ?? "Fuck") - .ConfigureAwait(false); + if (!(arg is Member addedMember)) return; + await JsRuntime.AlertAsync(addedMember?.CommonName ?? "Fuck").ConfigureAwait(false); } protected async Task OnSearchChanged(string arg) + { + AvailableMembers = await GetAvailableMembers(arg).ConfigureAwait(false); + } + + private async Task?> GetAvailableMembers(string arg) { var result = new List(); + if (string.IsNullOrWhiteSpace(arg)) return null; var users = await UsersRepository.GetAllAsync().ConfigureAwait(false); var securityGroups = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false); - result.AddRange(users.Where(x=> x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase) || x.FullName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase))); - result.AddRange(securityGroups.Where(x=> x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)).Where(x=> x.Id != SelectedSecurityGroup?.Id)); - AvailableMembers = result; + result.AddRange(users.Where(x => + x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase) || + x.FullName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase))); + result.AddRange(securityGroups + .Where(x => x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)) + .Where(x => x.Id != SelectedSecurityGroup?.Id)); + return result.Count == 0 ? null : result; } protected void OnButtonClicked(SecurityGroup securityGroup) diff --git a/UserService/Pages/Users.razor.cs b/UserService/Pages/Users.razor.cs index ebfe327..8b42244 100644 --- a/UserService/Pages/Users.razor.cs +++ b/UserService/Pages/Users.razor.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading.Tasks; using Blazorise; using Blazorise.DataGrid; -using Microsoft.JSInterop; using UserService.DatabaseLayer.Repositories; using UserService.Infrastructure.DataModels; using UserService.Infrastructure; @@ -31,7 +30,7 @@ namespace UserService.Pages Members ?? Enumerable.Empty()); if (mailValidation == true && commonNameValidation == true) return; - await JsRuntime.Alert("User could not be added").ConfigureAwait(false); + await JsRuntime.AlertAsync("User could not be added").ConfigureAwait(false); arg.Cancel = true; } @@ -46,7 +45,7 @@ namespace UserService.Pages protected override async Task RowDeletingCallback(CancellableRowChange arg) { if (arg == null) throw new ArgumentNullException(nameof(arg)); - var confirmed = await JsRuntime.Confirm($"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false); + var confirmed = await JsRuntime.ConfirmAsync($"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false); arg.Cancel = !confirmed; } diff --git a/nuget.config b/nuget.config index 9b18d88..6ce9759 100644 --- a/nuget.config +++ b/nuget.config @@ -4,6 +4,5 @@ -