80 lines
2.8 KiB
Plaintext
80 lines
2.8 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Users
|
|
@inherits ModuleBase
|
|
@inject IUserRoleService UserRoleService
|
|
@inject IUserService UserService
|
|
|
|
@if (userroles == null)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else
|
|
{
|
|
<ActionLink Action="Add" Text="Add User"/>
|
|
|
|
<div class="d-flex p-1">
|
|
<input class="form-control mr-4" @bind="@search"/><button class="btn btn-outline-primary ml-1" @onclick="OnSearch">Search</button>
|
|
</div>
|
|
|
|
<Pager Items="@userroles">
|
|
<Header>
|
|
<th> </th>
|
|
<th> </th>
|
|
<th> </th>
|
|
<th>Name</th>
|
|
</Header>
|
|
<Row>
|
|
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())" /></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>
|
|
}
|
|
|
|
@code {
|
|
private List<UserRole> allroles;
|
|
private List<UserRole> userroles;
|
|
private string search;
|
|
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
allroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
|
|
userroles = allroles.Where(item => item.Role.Name == Constants.RegisteredRole).ToList();
|
|
}
|
|
|
|
private void OnSearch()
|
|
{
|
|
userroles = allroles
|
|
.Where(item => item.Role.Name == Constants.RegisteredRole &&
|
|
(
|
|
item.User.Username.Contains(search, StringComparison.OrdinalIgnoreCase) ||
|
|
item.User.Email.Contains(search, StringComparison.OrdinalIgnoreCase) ||
|
|
item.User.DisplayName.Contains(search, StringComparison.OrdinalIgnoreCase)
|
|
)
|
|
)
|
|
.ToList();
|
|
}
|
|
|
|
|
|
private async Task DeleteUser(UserRole UserRole)
|
|
{
|
|
try
|
|
{
|
|
var 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);
|
|
}
|
|
}
|
|
}
|