<h3>Settings @_username</h3>
<div class="form-group">
<label for="roleSelect">Select Role:</label>
<select class="form-control" id="roleSelect" @bind="_selectedRoleValue" @oninput="OnSelectedRoleChanged">
<option value="">Select a role</option>
@foreach (var role in _allRoles.Where(r => r != "Super Admin"))
{
<option value="@role">@role</option>
}
</select>
@_selectedRoleValue
</div>
@if (!string.IsNullOrEmpty(_selectedRoleValue))
{
<h4>Permissions for selected role: @_selectedRoleValue</h4>
@foreach (var permission in _filteredPermissions)
{
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="@($"permission_{permission.Id}")" @bind="permission.CanCreatePost" />
<label class="form-check-label" for="@($"permission_{permission.Id}")">Create new category.</label>
</div>
}
}
@code {
private string test = "test";
private List<UserPermissions> _userPermissions = new List<UserPermissions>();
private List<UserPermissions> _filteredPermissions = new List<UserPermissions>();
private ApplicationUser _user = default!;
private string? _username;
private IList<string> _allRoles;
private string _selectedRoleValue = string.Empty;
private string? _phoneNumber;
protected override async Task OnInitializedAsync()
{
_user = await UserAccessor.GetRequiredUserAsync();
_username = await UserManager.GetUserNameAsync(_user);
_allRoles = await DbContext.Roles.Select(r => r.Name).ToListAsync();
foreach (var role in _allRoles)
{
var userPermission = await DbContext.UserPermissions
.Include(up => up.Role)
.Where(up => up.Role.Name == role)
.FirstOrDefaultAsync();