diff --git a/Libs/OAService.Domain.dll b/Libs/OAService.Domain.dll
index f7daef9..949a07b 100644
Binary files a/Libs/OAService.Domain.dll and b/Libs/OAService.Domain.dll differ
diff --git a/Libs/OAService.Infrastructure.dll b/Libs/OAService.Infrastructure.dll
index 1e994d1..3056703 100644
Binary files a/Libs/OAService.Infrastructure.dll and b/Libs/OAService.Infrastructure.dll differ
diff --git a/Libs/OAService.Service.dll b/Libs/OAService.Service.dll
index 4c8108d..5372de5 100644
Binary files a/Libs/OAService.Service.dll and b/Libs/OAService.Service.dll differ
diff --git a/StandManager/Components/Pages/Account/Login.razor b/StandManager/Components/Pages/Account/Login.razor
index d2a2e31..637665a 100644
--- a/StandManager/Components/Pages/Account/Login.razor
+++ b/StandManager/Components/Pages/Account/Login.razor
@@ -11,10 +11,7 @@
@using System.Security.Claims
@using StandManager.Service.Interfaces
-@inject StandManagerDbContext dbContext
-@inject NavigationManager navi
@inject IHttpContextAccessor HttpContextAccessor
-@inject IManagerService _managerService
@@ -79,12 +76,13 @@
var claims = new List
{
new Claim(ClaimTypes.Name, user.Email),
- new Claim(ClaimTypes.Role, "Admin")
+ new Claim(ClaimTypes.Role, "Admin"),
+ new Claim("UserId", user.Id.ToString())
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var principal = new ClaimsPrincipal(identity);
await httpContext.SignInAsync(principal);
- navi.NavigateTo("/management/dashboard");
+ _navManager.NavigateTo("/management/dashboard");
}
}
diff --git a/StandManager/Components/Pages/Management/Utenti.razor b/StandManager/Components/Pages/Management/Utenti.razor
index 1b5ea5c..f19855b 100644
--- a/StandManager/Components/Pages/Management/Utenti.razor
+++ b/StandManager/Components/Pages/Management/Utenti.razor
@@ -1,24 +1,61 @@
-@page "/management/Utenti"
-@using Microsoft.AspNetCore.Authorization
-@using StandManager.Domain.Entita
-@using StandManager.Service.Interfaces
-@inject IManagerService _managerService
-@attribute [Authorize]
-Utenti
+@attribute [Authorize]
+@page "/management/Utenti"
+@rendermode InteractiveServer
+Utenti
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@code {
IQueryable utenti;
+ RadzenDataGrid userGrid;
protected override async Task OnInitializedAsync()
{
@@ -26,4 +63,24 @@
utenti = await _managerService.UtenteService.RicercaQueryable(x => x.Eliminato == false);
}
-}
\ No newline at end of file
+
+ private async Task EditRow(Utente user)
+ {
+ _navManager.NavigateTo($"/management/Utenti/Modifica/{user.Id}");
+ }
+
+ private async Task DeleteRow(Utente user)
+ {
+
+ }
+
+ private async Task SaveRow(Utente user)
+ {
+
+ }
+
+ private async Task CancelEdit(Utente user)
+ {
+
+ }
+}
diff --git a/StandManager/Components/Pages/Management/Utenti_Edit.razor b/StandManager/Components/Pages/Management/Utenti_Edit.razor
new file mode 100644
index 0000000..1a8833e
--- /dev/null
+++ b/StandManager/Components/Pages/Management/Utenti_Edit.razor
@@ -0,0 +1,117 @@
+@attribute [Authorize]
+@rendermode InteractiveServer
+
+@page "/management/Utenti/Modifica"
+@page "/management/Utenti/Modifica/{UserId:guid}"
+
+@using Microsoft.AspNetCore.Identity
+@using StandManager.Model
+@inject AuthenticationStateProvider auth
+
+@pageTitle
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Nome
+
+
+
+
+ Cognome
+
+
+
+
+ Email
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@code {
+ [Parameter]
+ public Guid? UserId { get; set; }
+
+ [SupplyParameterFromForm]
+ private UtenteViewModel? utente { get; set; }
+
+ private string pageTitle => utente?.Id == Guid.Empty ? "Nuovo utente" : "Modifica utente";
+
+ protected override async Task OnInitializedAsync()
+ {
+ utente ??= await _managerService.UtenteService.RicercaPer(x => x.Id == UserId);
+ }
+
+ private async Task onUtenteSave()
+ {
+ var state = await auth.GetAuthenticationStateAsync();
+ var idClaim = state.User.FindFirst("UserId")?.Value;
+ if (string.IsNullOrEmpty(idClaim))
+ {
+ // gestisci errore (utente non autenticato o claim mancante)
+ return;
+ }
+
+ var model = await _managerService.UtenteService.RicercaPer(x => x.Id == utente.Id, solaLettura: false)
+ ?? new Utente();
+
+ model = utente.Map(model);
+
+ if (!string.IsNullOrWhiteSpace(utente.Password))
+ {
+ var hasher = new PasswordHasher();
+ model.Password = hasher.HashPassword(model, utente.Password);
+ }
+
+ await _managerService.UtenteService.Salva(model, Guid.Parse(idClaim));
+ _navManager.NavigateTo("/management/Utenti");
+ }
+}
diff --git a/StandManager/Components/_Imports.razor b/StandManager/Components/_Imports.razor
index e580f08..3f668d8 100644
--- a/StandManager/Components/_Imports.razor
+++ b/StandManager/Components/_Imports.razor
@@ -9,6 +9,12 @@
@using Microsoft.JSInterop
@using StandManager
@using StandManager.Components
+@using Microsoft.AspNetCore.Authorization
+@using StandManager.Domain.Entita
+@using StandManager.Service.Interfaces
@using Radzen
@using Radzen.Blazor
+
+@inject IManagerService _managerService
+@inject NavigationManager _navManager
\ No newline at end of file
diff --git a/StandManager/Model/UtenteViewModel.cs b/StandManager/Model/UtenteViewModel.cs
new file mode 100644
index 0000000..ec66d51
--- /dev/null
+++ b/StandManager/Model/UtenteViewModel.cs
@@ -0,0 +1,40 @@
+using StandManager.Domain.Entita;
+using System.ComponentModel.DataAnnotations;
+
+namespace StandManager.Model
+{
+ public class UtenteViewModel
+ {
+ public Guid Id { get; set; }
+ public string Username { get; set; }
+ //[Required]
+ //[EmailAddress(ErrorMessage = "Email non valida")]
+ public string Email { get; set; }
+ public string Password { get; set; }
+ //[Required(ErrorMessage ="Il nome è obbligatorio")]
+ public string Nome { get; set; }
+ //[Required(ErrorMessage = "Il cognome è obbligatorio")]
+ public string Cognome { get; set; }
+
+ public static implicit operator UtenteViewModel(Utente? model)
+ {
+ return model == null ? null : new UtenteViewModel
+ {
+ Id = model.Id,
+ Username = model.Username,
+ Email = model.Email,
+ Nome = model.Nome,
+ Cognome = model.Cognome
+ };
+ }
+
+ public Utente Map(Utente model)
+ {
+ model.Nome = Nome;
+ model.Cognome = Cognome;
+ model.Email = Email;
+
+ return model;
+ }
+ }
+}
diff --git a/StandManager/Program.cs b/StandManager/Program.cs
index 6fcf026..b01cdb0 100644
--- a/StandManager/Program.cs
+++ b/StandManager/Program.cs
@@ -84,11 +84,11 @@ else
app.UseHttpsRedirection();
app.UseStaticFiles();
-app.UseAntiforgery();
-
app.UseAuthentication();
app.UseAuthorization();
+app.UseAntiforgery();
+
app.MapRazorComponents()
.AddInteractiveServerRenderMode();