MailProcessor
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
@attribute [Authorize]
|
||||
@page "/management/Clienti"
|
||||
@using ClosedXML.Excel
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using StandManager.Model
|
||||
@using System.Threading.Tasks
|
||||
|
||||
@rendermode InteractiveServer
|
||||
|
||||
|
||||
108
StandManager/Components/Pages/Management/Profile.razor
Normal file
108
StandManager/Components/Pages/Management/Profile.razor
Normal file
@ -0,0 +1,108 @@
|
||||
@page "/management/profile"
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using StandManager.Model
|
||||
|
||||
@attribute [Authorize]
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<div class="page-wrapper">
|
||||
<!-- BEGIN PAGE BODY -->
|
||||
<div class="page-body">
|
||||
<div class="container-xl">
|
||||
<div class="row row-cards">
|
||||
<div class="col-12">
|
||||
<div class="row">
|
||||
<!-- Page pre-title -->
|
||||
<div class="page-pretitle"> </div>
|
||||
<h2 class="page-title">Profilo</h2>
|
||||
</div>
|
||||
</div>
|
||||
<EditForm Model="profilo" OnValidSubmit="onProfiloSave" FormName="profiloForm">
|
||||
<div class="col-12">
|
||||
<div class="row">
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">Nome</RadzenText>
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Nome" @bind-Value="@profilo.Nome" />
|
||||
</div>
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">Cognome</RadzenText>
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Cognome" @bind-Value="@profilo.Cognome" />
|
||||
</div>
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">Email</RadzenText>
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Email" @bind-Value="@profilo.Email" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">Password</RadzenText>
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Password" @bind-Value="@profilo.Password" Placeholder="Compila questo campo solo se desideri modificare la password." />
|
||||
</div>
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">Conferma Password</RadzenText>
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Nome" @bind-Value="@profilo.ConfirmPassword" Placeholder="Compila questo campo solo se desideri modificare la password." />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4 mb-3">
|
||||
<button type="button" class="btn btn-default w-100" @onclick="backToHome">
|
||||
Annulla
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4 mb-3">
|
||||
<button type="submit" class="btn btn-primary w-100">
|
||||
Salva
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@code{
|
||||
[SupplyParameterFromForm]
|
||||
private ProfiloViewModel profilo { get; set; } = new();
|
||||
private Guid userId = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
userId = await MembershipUtils.GetUserId(_auth);
|
||||
|
||||
profilo = await _managerService.UtenteService
|
||||
.RicercaPer(x => x.Id == userId);
|
||||
}
|
||||
|
||||
private async Task onProfiloSave()
|
||||
{
|
||||
try
|
||||
{
|
||||
profilo.Validate();
|
||||
var user = await _managerService.UtenteService.RicercaPer(x => x.Id == userId, solaLettura: false);
|
||||
user = profilo.Map(user);
|
||||
if (!string.IsNullOrEmpty(profilo.Password))
|
||||
{
|
||||
var hasher = new PasswordHasher<Utente>();
|
||||
user.Password = hasher.HashPassword(user, profilo.Password);
|
||||
}
|
||||
await _managerService.UtenteService.Salva(user, userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _dialogService.Alert(ex.Message, "Errore");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Torna alla pagina di elenco clienti senza salvare altre modifiche.
|
||||
/// </summary>
|
||||
private void backToHome()
|
||||
{
|
||||
_navManager.NavigateTo("/management");
|
||||
}
|
||||
}
|
||||
47
StandManager/Model/ProfiloViewModel.cs
Normal file
47
StandManager/Model/ProfiloViewModel.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OAService.Domain.Entita;
|
||||
using StandManager.Domain.Entita;
|
||||
|
||||
namespace StandManager.Model;
|
||||
|
||||
public class ProfiloViewModel
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string Nome { get; set; }
|
||||
public string Cognome { get; set; }
|
||||
|
||||
public static implicit operator ProfiloViewModel(Utente model)
|
||||
{
|
||||
return model == null
|
||||
? null
|
||||
: new ProfiloViewModel()
|
||||
{
|
||||
Cognome = model.Cognome,
|
||||
Nome = model.Nome,
|
||||
Email = model.Email,
|
||||
Username = model.Username,
|
||||
Id = model.Id
|
||||
};
|
||||
}
|
||||
|
||||
public Utente Map(Utente user)
|
||||
{
|
||||
user.Nome = Nome;
|
||||
user.Cognome = Cognome;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Nome)) throw new ValidationException("Il nome inserito non è valido");
|
||||
if (string.IsNullOrEmpty(Cognome)) throw new ValidationException("Il cognome inserito non è valido");
|
||||
if (!string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(ConfirmPassword)) throw new Exception("E' necessario inserire la password di conferma");
|
||||
if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(ConfirmPassword) && Password != ConfirmPassword)
|
||||
throw new ValidationException("Le due password non corrispondono");
|
||||
}
|
||||
}
|
||||
@ -1,49 +1,47 @@
|
||||
using StandManager.Domain.Entita;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace StandManager.Model
|
||||
namespace StandManager.Model;
|
||||
|
||||
public class UtenteViewModel
|
||||
{
|
||||
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 Guid RuoloId { get; set; }
|
||||
public Guid CapoareaId { get; set; }
|
||||
public bool IsCapoarea { get; set; }
|
||||
public string Info => $"{Nome} {Cognome}";
|
||||
|
||||
public static implicit operator UtenteViewModel(Utente? model)
|
||||
{
|
||||
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 Guid RuoloId { get; set; }
|
||||
public Guid CapoareaId { get; set; }
|
||||
public bool IsCapoarea { get; set; }
|
||||
public string Info => $"{Nome} {Cognome}";
|
||||
|
||||
public static implicit operator UtenteViewModel(Utente? model)
|
||||
return model == null ? null : new UtenteViewModel
|
||||
{
|
||||
return model == null ? null : new UtenteViewModel
|
||||
{
|
||||
Id = model.Id,
|
||||
Username = model.Username,
|
||||
Email = model.Email,
|
||||
Nome = model.Nome,
|
||||
Cognome = model.Cognome,
|
||||
RuoloId = model.Ruolo?.Id ?? Guid.Empty,
|
||||
CapoareaId = model.Capoarea?.Id ?? Guid.Empty,
|
||||
IsCapoarea = model.IsCapoarea
|
||||
};
|
||||
}
|
||||
Id = model.Id,
|
||||
Username = model.Username,
|
||||
Email = model.Email,
|
||||
Nome = model.Nome,
|
||||
Cognome = model.Cognome,
|
||||
RuoloId = model.Ruolo?.Id ?? Guid.Empty,
|
||||
CapoareaId = model.Capoarea?.Id ?? Guid.Empty,
|
||||
IsCapoarea = model.IsCapoarea
|
||||
};
|
||||
}
|
||||
|
||||
public Utente Map(Utente model)
|
||||
{
|
||||
model.Nome = Nome;
|
||||
model.Cognome = Cognome;
|
||||
model.Email = Email;
|
||||
model.IsCapoarea = IsCapoarea;
|
||||
public Utente Map(Utente model)
|
||||
{
|
||||
model.Nome = Nome;
|
||||
model.Cognome = Cognome;
|
||||
model.Email = Email;
|
||||
model.IsCapoarea = IsCapoarea;
|
||||
|
||||
return model;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user