Fix metodi await x users
This commit is contained in:
@@ -127,9 +127,18 @@
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary" @onclick="(() => EditUser(user.Identity))" title="Edit">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
@if (!ShowPopup)
|
||||
{
|
||||
<button class="btn btn-sm btn-primary" @onclick="(() => EditUser(user.Identity))" title="Edit">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-secondary disabled" title="Edit">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
<td>@user.Identity.Id.Substring(0, 4)...</td>
|
||||
@*<td>@user.UserName</td>*@
|
||||
@@ -138,16 +147,21 @@
|
||||
@ShowRoles(user.Roles)
|
||||
</td>
|
||||
<td>
|
||||
@*@if (!ShowPopup)
|
||||
{
|
||||
@GetClaims(user.Identity)
|
||||
}*@
|
||||
@ShowClaims(user.Claims)
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-danger" @onclick="DeleteUser" title="Delete">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
@if (!ShowPopup)
|
||||
{
|
||||
<button class="btn btn-sm btn-danger" @onclick="(() => DeleteUser(user.Identity))" title="Delete">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-secondary disabled" title="Delete">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace GWMS.User.Pages
|
||||
{
|
||||
@@ -20,8 +21,6 @@ namespace GWMS.User.Pages
|
||||
/// </summary>
|
||||
private List<string> ClaimsList = new List<string>() { STD_CLAIM, "PlantId", "SupplierId", "TransporterId" };
|
||||
|
||||
private System.Security.Claims.ClaimsPrincipal CurrentUser;
|
||||
|
||||
/// <summary>
|
||||
/// User corrente
|
||||
/// </summary>
|
||||
@@ -91,6 +90,9 @@ namespace GWMS.User.Pages
|
||||
[Inject]
|
||||
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; }
|
||||
|
||||
[Inject]
|
||||
protected IJSRuntime JSRuntime { get; set; }
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Methods
|
||||
@@ -106,27 +108,31 @@ namespace GWMS.User.Pages
|
||||
ShowPopup = true;
|
||||
}
|
||||
|
||||
private void ClosePopup()
|
||||
private async Task ClosePopup()
|
||||
{
|
||||
// Close the Popup
|
||||
ShowPopup = false;
|
||||
// Refresh Users
|
||||
GetUsers();
|
||||
await GetUsers();
|
||||
}
|
||||
|
||||
private async Task DeleteUser()
|
||||
private async Task DeleteUser(IdentityUser _IdentityUser)
|
||||
{
|
||||
// Close the Popup
|
||||
ShowPopup = false;
|
||||
|
||||
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare l'utente selezionato??"))
|
||||
return;
|
||||
|
||||
// Get the user
|
||||
var user = await _UserManager.FindByIdAsync(objUser.Id);
|
||||
var user = await _UserManager.FindByIdAsync(_IdentityUser.Id);
|
||||
if (user != null)
|
||||
{
|
||||
// Delete the user
|
||||
await _UserManager.DeleteAsync(user);
|
||||
}
|
||||
// Refresh Users
|
||||
GetUsers();
|
||||
await GetUsers();
|
||||
}
|
||||
|
||||
private void EditUser(IdentityUser _IdentityUser)
|
||||
@@ -291,7 +297,7 @@ namespace GWMS.User.Pages
|
||||
// Close the Popup
|
||||
ShowPopup = false;
|
||||
// Refresh Users
|
||||
GetUsers();
|
||||
await GetUsers();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -306,7 +312,7 @@ namespace GWMS.User.Pages
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Get the users
|
||||
GetUsers();
|
||||
await GetUsers();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
@@ -322,39 +328,10 @@ namespace GWMS.User.Pages
|
||||
{
|
||||
}
|
||||
|
||||
public string GetClaims(IdentityUser user)
|
||||
{
|
||||
string answ = "";
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
// Gestione salvataggio ruoli... SE VARIATO...
|
||||
var UserClaims = await _UserManager.GetClaimsAsync(user);
|
||||
if (UserClaims != null && UserClaims.Count > 0)
|
||||
{
|
||||
answ = string.Join(",", UserClaims);
|
||||
}
|
||||
});
|
||||
pUpd.Wait();
|
||||
return answ;
|
||||
}
|
||||
|
||||
public string GetRole(IdentityUser user)
|
||||
{
|
||||
string answ = "";
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
// Gestione salvataggio ruoli... SE VARIATO...
|
||||
var UserRoles = await _UserManager.GetRolesAsync(user);
|
||||
if (UserRoles != null && UserRoles.Count > 0)
|
||||
{
|
||||
answ = UserRoles.FirstOrDefault();
|
||||
}
|
||||
});
|
||||
pUpd.Wait();
|
||||
return answ;
|
||||
}
|
||||
|
||||
public void GetUsers()
|
||||
/// <summary>
|
||||
/// Recupera elenco utenti
|
||||
/// </summary>
|
||||
public async Task GetUsers()
|
||||
{
|
||||
// clear any error messages
|
||||
strError = "";
|
||||
@@ -373,21 +350,14 @@ namespace GWMS.User.Pages
|
||||
|
||||
foreach (var item in user)
|
||||
{
|
||||
List<string> UserRoles = new List<string>();
|
||||
List<System.Security.Claims.Claim> UserClaims = new List<System.Security.Claims.Claim>();
|
||||
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
UserRoles = (List<string>)await _UserManager.GetRolesAsync(item);
|
||||
UserClaims = (List<System.Security.Claims.Claim>)await _UserManager.GetClaimsAsync(item);
|
||||
});
|
||||
pUpd.Wait();
|
||||
var UserRoles = await _UserManager.GetRolesAsync(item);
|
||||
var UserClaims = await _UserManager.GetClaimsAsync(item);
|
||||
|
||||
var newItem = new UserData()
|
||||
{
|
||||
Identity = item,
|
||||
Roles = UserRoles,
|
||||
Claims = UserClaims
|
||||
Roles = UserRoles.ToList(),
|
||||
Claims = UserClaims.ToList()
|
||||
};
|
||||
UsersList.Add(newItem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user