modified all admin UIs to position action buttons on the left side of grids and implemented ActionDialog throughout rather than dedicated delete components

This commit is contained in:
Shaun Walker
2019-11-04 23:29:35 -05:00
parent 156f5b5f94
commit ab564f7244
32 changed files with 737 additions and 732 deletions

View File

@ -1,6 +1,7 @@
@namespace Oqtane.Modules.Admin.Users
@inherits ModuleBase
@inject IUserRoleService UserRoleService
@inject IUserService UserService
@if (userroles == null)
{
@ -8,20 +9,20 @@
}
else
{
<ActionLink Action="Add" Text="Add User" Style="float: right; margin: 10px;" />
<ActionLink Action="Add" Text="Add User" />
<Pager Items="@userroles">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Name</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.User.DisplayName</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + context.UserId.ToString())" Class="btn btn-danger" /></td>
<td><ActionDialog Header="Delete User" Message="@("Are You Sure You Wish To Delete " + context.User.DisplayName + "?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteUser(context))" /></td>
<td><ActionLink Action="Roles" Parameters="@($"id=" + context.UserId.ToString())" /></td>
<td>@context.User.DisplayName</td>
</Row>
</Pager>
}
@ -36,4 +37,23 @@ else
userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
userroles = userroles.Where(item => item.Role.Name == Constants.RegisteredRole).ToList();
}
private async Task DeleteUser(UserRole UserRole)
{
try
{
User user = await UserService.GetUserAsync(UserRole.UserId, PageState.Site.SiteId);
if (user != null)
{
await UserService.DeleteUserAsync(user.UserId);
await logger.LogInformation("User Deleted {User}", UserRole.User);
StateHasChanged();
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting User {User} {Error}", UserRole.User, ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
}
}