Skip to content

Commit

Permalink
use FindByNamesAsync more
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Jan 7, 2025
1 parent 723e2e1 commit add66ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public override IDisplayResult Edit(LinkAdminNode treeNode, BuildEditorContext c
model.IconClass = treeNode.IconClass;
model.Target = treeNode.Target;

var permissions = await _permissionService.GetPermissionsAsync();

var selectedPermissions = await _permissionService.FindByNamesAsync(treeNode.PermissionNames);

model.SelectedItems = selectedPermissions
Expand All @@ -41,6 +39,9 @@ public override IDisplayResult Edit(LinkAdminNode treeNode, BuildEditorContext c
Name = p.Name,
DisplayText = p.Description
}).ToArray();

var permissions = await _permissionService.GetPermissionsAsync();

model.AllItems = permissions
.Select(p => new PermissionViewModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public override IDisplayResult Edit(PlaceholderAdminNode treeNode, BuildEditorCo
model.LinkText = treeNode.LinkText;
model.IconClass = treeNode.IconClass;

var permissions = await _permissionService.GetPermissionsAsync();

var selectedPermissions = await _permissionService.FindByNamesAsync(treeNode.PermissionNames);

model.SelectedItems = selectedPermissions
Expand All @@ -39,6 +37,9 @@ public override IDisplayResult Edit(PlaceholderAdminNode treeNode, BuildEditorCo
Name = p.Name,
DisplayText = p.Description
}).ToArray();

var permissions = await _permissionService.GetPermissionsAsync();

model.AllItems = permissions
.Select(p => new PermissionViewModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public override IDisplayResult Edit(MenuItemPermissionPart part, BuildPartEditor
{
return Initialize<MenuItemPermissionViewModel>("MenuItemPermissionPart_Edit", async model =>
{
var permissions = await _permissionService.GetPermissionsAsync();

var selectedPermissions = permissions.Where(p => part.PermissionNames.Contains(p.Name));
var selectedPermissions = await _permissionService.FindByNamesAsync(part.PermissionNames);

model.SelectedItems = selectedPermissions
.Select(p => new PermissionViewModel
Expand All @@ -31,6 +29,8 @@ public override IDisplayResult Edit(MenuItemPermissionPart part, BuildPartEditor
DisplayText = p.Description
}).ToArray();

var permissions = await _permissionService.GetPermissionsAsync();

model.AllItems = permissions
.Select(p => new PermissionViewModel
{
Expand All @@ -50,10 +50,9 @@ await context.Updater.TryUpdateModelAsync(model, Prefix,
? []
: model.SelectedPermissionNames.Split(',', StringSplitOptions.RemoveEmptyEntries);

var permissions = await _permissionService.GetPermissionsAsync();
part.PermissionNames = permissions
.Where(p => selectedPermissions.Contains(p.Name))
.Select(p => p.Name).ToArray();
var permissions = await _permissionService.FindByNamesAsync(selectedPermissions);

part.PermissionNames = permissions.Select(x => x.Name).ToArray();

return Edit(part, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ public async ValueTask<Permission> FindByNameAsync(string name)

public async ValueTask<IEnumerable<Permission>> GetPermissionsAsync()
{
if (_permissions != null)
if (_permissions == null)
{
return _permissions.Values;
await LoadPermissionsAsync();
}

await LoadPermissionsAsync();

return _permissions.Values;
}

Expand Down

0 comments on commit add66ae

Please sign in to comment.