- Ottimizzazione codice
This commit is contained in:
@ -48,7 +48,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4 mb-3">
|
||||
<RadzenFormField Text="Provincia" Variant="Variant.Flat" Style="width: 100%;">
|
||||
<RadzenDropDown TValue="Guid ?" @bind-bind-Value="@iscrizione.ProvinciaId" Change="@(args => onProvinciaChanged(args))" Style="width: 100%" TextProperty="Info" ValueProperty="Id" Placeholder="Seleziona la provincia"
|
||||
<RadzenDropDown TValue="Guid ?" @bind-Value="@iscrizione.ProvinciaId" Change="@(args => onProvinciaChanged(args))" Style="width: 100%" TextProperty="Info" ValueProperty="Id" Placeholder="Seleziona la provincia"
|
||||
Data="@provList" Size="ButtonSize.Small" />
|
||||
</RadzenFormField>
|
||||
<ValidationMessage For="@(() => iscrizione.ProvinciaId)" />
|
||||
@ -116,7 +116,7 @@
|
||||
{
|
||||
<div class="col-6 mb-3">
|
||||
<RadzenFormField Text="Destinazione" Variant="Variant.Flat" Style="width: 100%;">
|
||||
<RadzenDropDown @bind-Value="@iscrizione.DestinazioneId" TValue="Guid?" Style="width: 100%" ValueProperty="Id" TextProperty="Info" Placeholder="Seleziona la destinazione"
|
||||
<RadzenDropDown @bind-Value="@iscrizione.DestinazioneId" TValue="Guid ?" Style="width: 100%" ValueProperty="Id" TextProperty="Info" Placeholder="Seleziona la destinazione"
|
||||
Data="@destinazioniList" Size="ButtonSize.Small" />
|
||||
</RadzenFormField>
|
||||
</div>
|
||||
@ -141,7 +141,7 @@
|
||||
<div class="d-flex align-items-center">
|
||||
<RadzenCheckBox class="form-check-input" @bind-Value="presaVisioneDatiPersonali" Name="presaVisioneDatiPersonali" TValue="bool" />
|
||||
<label class="rz-ms-2" for="presaVisioneDatiPersonali" style="cursor: pointer;">
|
||||
Autorizzazione al trattamento dati*<br/>
|
||||
Autorizzazione al trattamento dati*<br />
|
||||
I dati forniti saranno utilizzati esclusivamente per l’invio del biglietto. (<a href="https://www.gruppodac.eu/tutela-e-privacy/" target="_blank">leggi</a>)
|
||||
</label>
|
||||
</div>
|
||||
@ -200,10 +200,19 @@
|
||||
? await _managerService.EventoService.RicercaPer(x => x.Id == invito.EventoId)
|
||||
: (await _managerService.EventoService.RicercaQueryable(x => x.DataA > DateTime.Now,
|
||||
ordinamento: y => y.OrderBy(z => z.DataA))).FirstOrDefault();
|
||||
|
||||
inizioEvento = evento?.DataDa ?? DateTime.Now.AddDays(-7);
|
||||
fineEvento = evento?.DataA ?? DateTime.Now.AddDays(7);
|
||||
|
||||
if (!hasCliente)
|
||||
NoCliente();
|
||||
else
|
||||
HasCliente();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Funzione di salvataggio, mappa i dati e aggiunge gli ids per le FK
|
||||
/// </summary>
|
||||
private async Task onIscrizioneSave()
|
||||
{
|
||||
var userId = await MembershipUtils.GetUserId(_auth);
|
||||
@ -228,6 +237,9 @@
|
||||
_navManager.NavigateTo($"/Grazie");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imposta i dati cliente al cambio della Partita IVA
|
||||
/// </summary>
|
||||
public async Task SetDatiCliente()
|
||||
{
|
||||
iscrizione.DestinazioneId = invito.DestinazioneId;
|
||||
@ -245,6 +257,7 @@
|
||||
{
|
||||
destinazioniList = new List<DestinazioneViewModel>() { new() { RagioneSociale = "--Nessuna" } };
|
||||
iscrizione.EsperienzaConDAC = "No";
|
||||
|
||||
}
|
||||
|
||||
public void HasCliente()
|
||||
@ -252,6 +265,9 @@
|
||||
iscrizione.EsperienzaConDAC = "Si";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna i comuni in base alla provincia selezionata
|
||||
/// </summary>
|
||||
private async Task onProvinciaChanged(object args)
|
||||
{
|
||||
Guid parsed;
|
||||
@ -271,6 +287,10 @@
|
||||
.Select(x => (ComuneIstatViewModel)x).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serve per aggiornare i dati del form se ci troviamo nella situazione in cui il cliente è salvato a db
|
||||
/// Attiva la compilazione solo se siamo nel form e da UI chi compila ci dice che è già stato cliente
|
||||
/// </summary>
|
||||
private async Task onCodiceFornitoChanged(string text)
|
||||
{
|
||||
if (!hasCliente) return;
|
||||
|
||||
@ -212,7 +212,7 @@
|
||||
idClaim = await MembershipUtils.GetUserId(auth);
|
||||
var idRuolo = await MembershipUtils.GetRoleId(auth);
|
||||
var ruolo = await _managerService.RuoloService.RicercaPer(
|
||||
x => x.Id == idRuolo && x.Permessi.Any(y => y.Feature.Type == FeatureType.Capoarea || y.Feature.Type == FeatureType.AdminGlobal),
|
||||
x => x.Id == idRuolo && x.Permessi.Any(y => y.Feature.Type == FeatureType.Capoarea || y.Feature.Type == FeatureType.AdminGlobal),
|
||||
includi: x => x.Include(y => y.Permessi).ThenInclude(z => z.Feature));
|
||||
|
||||
isAdmin = ruolo?.Permessi.Where(x => x.Eliminato == false)?.Any(x => x.Feature.Type == FeatureType.AdminGlobal) ?? false;
|
||||
@ -227,14 +227,14 @@
|
||||
esperienzaList = new List<string>() { "Si", "No" };
|
||||
tipologiaList = (await _managerService.TipologiaClienteService.RicercaQueryable(x => x.Eliminato == false, ordinamento: x => x.OrderBy(y => y.Nome))).Select(x => new LookupViewModel<Guid>(x.Id, x.Nome)).ToList();
|
||||
ruoloList = eUtils.GetEnumList<RuoloTipo>();
|
||||
provList = (await _managerService.ProvinciaIstatService.RicercaQueryable(x => x.Eliminato == false,ordinamento: x => x.OrderBy(y => y.Provincia))).Select(x => (ProvinciaViewModel)x).ToList();
|
||||
provList = (await _managerService.ProvinciaIstatService.RicercaQueryable(x => x.Eliminato == false, ordinamento: x => x.OrderBy(y => y.Provincia))).Select(x => (ProvinciaViewModel)x).ToList();
|
||||
comuniList = (await _managerService.ComuneIstatService.RicercaQueryable(x => x.ProvinciaIstatId == iscrizione.ProvinciaId.GetValueOrDefault())).Select(x => (ComuneIstatViewModel)x).ToList();
|
||||
|
||||
capoareaId = iscrizione.CapoareaId.GetValueOrDefault();
|
||||
capiarea = (await _managerService.UtenteService.RicercaQueryable(
|
||||
x => x.Eliminato == false && x.IsCapoarea, ordinamento: x => x.OrderBy(y => y.Cognome).ThenBy(z => z.Nome))).Select(x => (UtenteViewModel)x).ToList();
|
||||
|
||||
if(capoareaId != Guid.Empty)
|
||||
if (capoareaId != Guid.Empty)
|
||||
agenti = (await _managerService.UtenteService.RicercaQueryable(
|
||||
x => x.Eliminato == false && (isAdmin || x.CapoareaId == idClaim) && !x.IsCapoarea && x.CapoareaId == iscrizione.CapoareaId,
|
||||
includi: x => x.Include(y => y.Capoarea), ordinamento: x => x.OrderBy(y => y.Cognome).ThenBy(z => z.Nome))).Select(x => (UtenteViewModel)x).ToList();
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
@using System.Globalization
|
||||
@using System.IO
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using StandManager.Model
|
||||
@attribute [Authorize]
|
||||
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@inject AuthenticationStateProvider auth
|
||||
|
||||
<RadzenStack Gap="1rem" class="rz-m-12">
|
||||
<RadzenProgressBar Value="@counter" Max="@utentiTotali" Unit="@counterLabel" AriaLabel="" />
|
||||
</RadzenStack>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] private Dialog _dialog { get; set; }
|
||||
[Parameter] public UploadChangeEventArgs args { get; set; }
|
||||
|
||||
private int utentiTotali { get; set; } = 0;
|
||||
private int counter { get; set; } = 0;
|
||||
private string counterLabel { get; set; } = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
base.OnInitializedAsync();
|
||||
var file = args.Files.FirstOrDefault();
|
||||
await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||
var idClaim = await MembershipUtils.GetUserId(auth);
|
||||
|
||||
await using var ms = new MemoryStream();
|
||||
await uploadStream.CopyToAsync(ms);
|
||||
ms.Position = 0;
|
||||
|
||||
using var reader = new StreamReader(ms, System.Text.Encoding.UTF8);
|
||||
|
||||
var mailDictionary = new Dictionary<string, string>();
|
||||
|
||||
bool isHeader = true;
|
||||
string line;
|
||||
|
||||
while ((line = await reader.ReadLineAsync()) != null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
|
||||
if (isHeader)
|
||||
{
|
||||
isHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var parts = line.Split(',');
|
||||
|
||||
if (parts.Length >= 2)
|
||||
{
|
||||
var code = parts[0];
|
||||
var mail = parts[1];
|
||||
|
||||
if (!string.IsNullOrEmpty(code) && !mailDictionary.ContainsKey(code))
|
||||
{
|
||||
mailDictionary.Add(code, mail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var listaUtenti = await (await _managerService.UtenteService.RicercaQueryable(x => !x.Eliminato, solaLettura: false)).ToListAsync();
|
||||
|
||||
utentiTotali = listaUtenti.Count;
|
||||
counterLabel = " utenti analizzati";
|
||||
|
||||
foreach (var utente in listaUtenti)
|
||||
{
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(utente.CodiceAgente) && mailDictionary.TryGetValue(utente.CodiceAgente, out string nuovaMail) && !string.IsNullOrWhiteSpace(nuovaMail) && utente.Email != nuovaMail)
|
||||
{
|
||||
utente.Email = nuovaMail;
|
||||
await _managerService.UtenteService.Salva(utente, idClaim);
|
||||
}
|
||||
|
||||
counter++;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
ms.Close();
|
||||
_dialogService.Close();
|
||||
}
|
||||
|
||||
// Classe per mappare le colonne del CSV
|
||||
private class CSVMail
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Mail { get; set; }
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,9 @@
|
||||
</div>
|
||||
<div class="col-auto ms-auto">
|
||||
<div class="btn-list">
|
||||
|
||||
<RadzenUpload class="btn-5 d-none d-sm-inline-block" Change=@onUpload ChooseText="Importa mail utenti da CSV" />
|
||||
|
||||
<a href="/management/Utenti/Modifica" class="btn btn-primary btn-5 d-none d-sm-inline-block">
|
||||
Nuovo utente
|
||||
</a>
|
||||
@ -57,6 +60,7 @@
|
||||
@code {
|
||||
IQueryable<Utente> utenti;
|
||||
RadzenDataGrid<Utente> userGrid;
|
||||
private Ruolo? ruolo;
|
||||
|
||||
/// <summary>
|
||||
/// Carica la lista degli utenti non eliminati, ordinandoli per cognome e nome.
|
||||
@ -96,4 +100,25 @@
|
||||
ordinamento: x => x.OrderBy(y => y.Cognome).ThenBy(z => z.Nome));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task onUpload(UploadChangeEventArgs args)
|
||||
{
|
||||
var file = args.Files.FirstOrDefault();
|
||||
if (file == null ||
|
||||
!file.Name.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await _dialogService.Alert("Sono supportati solo file CSV .csv", "Errore");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
// await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||
await _dialogService.OpenAsync<Mail_Utenti_Import>("Importazione mail per utenti", new Dictionary<string, object>() { { "args", args } });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var er = ex.Message;
|
||||
await _dialogService.Alert("Si è verificato un errore durante l'importazione del file.", "Errore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,18 +13,6 @@
|
||||
|
||||
<div class="container my-5 py-3">
|
||||
<ClienteToggle ValueChanged="onClienteToggleChanged" />
|
||||
@* @if (showCodiceCliente)
|
||||
{
|
||||
<div class="col-12">
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
<RadzenFormField Text="Codice cliente o Partita IVA" Variant="Variant.Flat" Style="width: 100%;">
|
||||
<RadzenTextBox Style="width: 100%" aria-label="Codice cliente o Partita IVA" Change="(args => onCodiceFornitoChanged(args))" />
|
||||
</RadzenFormField>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} *@
|
||||
|
||||
@if (showForm)
|
||||
{
|
||||
@ -42,8 +30,6 @@
|
||||
private Component_Registrazione registrazione { get; set; } = new();
|
||||
private bool hasCliente { get; set; }
|
||||
|
||||
private string codiceFornito { get; set; }
|
||||
|
||||
private void onClienteToggleChanged(bool value)
|
||||
{
|
||||
if (!value)
|
||||
@ -59,30 +45,6 @@
|
||||
|
||||
showCodiceCliente = value;
|
||||
showForm = true;
|
||||
}
|
||||
|
||||
private async Task onCodiceFornitoChanged(string text)
|
||||
{
|
||||
codiceFornito = text;
|
||||
invito.CodiceFornito = codiceFornito;
|
||||
|
||||
var destinazione = (await _managerService.DestinazioneService.RicercaPer(
|
||||
x => x.PartitaIva == codiceFornito || x.CodiceFiscale == codiceFornito || x.Rid == codiceFornito || x.Cliente.Rid == codiceFornito,
|
||||
includi: x => x.Include(y => y.Cliente)));
|
||||
|
||||
if (destinazione == null || string.IsNullOrEmpty(text))
|
||||
{
|
||||
await _dialogService.Alert("Non è stato trovato il clente (Codice cliente/Partita IVA non presente)", "Errore", new ConfirmOptions() { OkButtonText = "Ok" });
|
||||
}
|
||||
else
|
||||
{
|
||||
invito.ClienteId = destinazione.ClienteId;
|
||||
invito.DestinazioneId = destinazione.Id;
|
||||
invito.CodiceFornito = codiceFornito;
|
||||
invito.RagioneSociale = destinazione.Cliente?.RagioneSociale ?? string.Empty;
|
||||
await registrazione.SetDatiCliente();
|
||||
}
|
||||
|
||||
showForm = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@ -28,46 +28,6 @@
|
||||
private Component_Registrazione registrazione { get; set; } = new();
|
||||
private bool hasCliente { get; set; }
|
||||
|
||||
private string codiceFornito { get; set; }
|
||||
|
||||
private void onClienteToggleChanged(bool value)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
hasCliente = false;
|
||||
registrazione.NoCliente();
|
||||
}
|
||||
else
|
||||
{
|
||||
hasCliente = true;
|
||||
registrazione.HasCliente();
|
||||
}
|
||||
|
||||
showCodiceCliente = value;
|
||||
showForm = true;
|
||||
}
|
||||
|
||||
private async Task onCodiceFornitoChanged(string text)
|
||||
{
|
||||
codiceFornito = text;
|
||||
invito.CodiceFornito = codiceFornito;
|
||||
|
||||
var destinazione = (await _managerService.DestinazioneService.RicercaPer(
|
||||
x => x.PartitaIva == codiceFornito || x.CodiceFiscale == codiceFornito || x.Rid == codiceFornito || x.Cliente.Rid == codiceFornito,
|
||||
includi: x => x.Include(y => y.Cliente)));
|
||||
|
||||
if (destinazione != null)
|
||||
{
|
||||
invito.ClienteId = destinazione.ClienteId;
|
||||
invito.DestinazioneId = destinazione.Id;
|
||||
invito.CodiceFornito = codiceFornito;
|
||||
invito.RagioneSociale = destinazione.Cliente?.RagioneSociale ?? string.Empty;
|
||||
await registrazione.SetDatiCliente();
|
||||
}
|
||||
|
||||
showForm = true;
|
||||
}
|
||||
|
||||
private async Task onSubmitCompleted(IscrizioneEvento model)
|
||||
{
|
||||
var queue = new MailQueue()
|
||||
|
||||
Reference in New Issue
Block a user