diff --git a/StandManager/Components/Pages/Component_Registrazione.razor b/StandManager/Components/Pages/Component_Registrazione.razor index a5f8cbf..7b64bd9 100644 --- a/StandManager/Components/Pages/Component_Registrazione.razor +++ b/StandManager/Components/Pages/Component_Registrazione.razor @@ -48,7 +48,7 @@
- @@ -116,7 +116,7 @@ {
-
@@ -141,7 +141,7 @@
@@ -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(); } + /// + /// Funzione di salvataggio, mappa i dati e aggiunge gli ids per le FK + /// private async Task onIscrizioneSave() { var userId = await MembershipUtils.GetUserId(_auth); @@ -228,6 +237,9 @@ _navManager.NavigateTo($"/Grazie"); } + /// + /// Imposta i dati cliente al cambio della Partita IVA + /// public async Task SetDatiCliente() { iscrizione.DestinazioneId = invito.DestinazioneId; @@ -245,6 +257,7 @@ { destinazioniList = new List() { new() { RagioneSociale = "--Nessuna" } }; iscrizione.EsperienzaConDAC = "No"; + } public void HasCliente() @@ -252,6 +265,9 @@ iscrizione.EsperienzaConDAC = "Si"; } + /// + /// Aggiorna i comuni in base alla provincia selezionata + /// private async Task onProvinciaChanged(object args) { Guid parsed; @@ -271,6 +287,10 @@ .Select(x => (ComuneIstatViewModel)x).ToList(); } + /// + /// 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 + /// private async Task onCodiceFornitoChanged(string text) { if (!hasCliente) return; diff --git a/StandManager/Components/Pages/Management/Iscrizioni_Edit.razor b/StandManager/Components/Pages/Management/Iscrizioni_Edit.razor index 553b26d..48f5fbe 100644 --- a/StandManager/Components/Pages/Management/Iscrizioni_Edit.razor +++ b/StandManager/Components/Pages/Management/Iscrizioni_Edit.razor @@ -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() { "Si", "No" }; tipologiaList = (await _managerService.TipologiaClienteService.RicercaQueryable(x => x.Eliminato == false, ordinamento: x => x.OrderBy(y => y.Nome))).Select(x => new LookupViewModel(x.Id, x.Nome)).ToList(); ruoloList = eUtils.GetEnumList(); - 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(); diff --git a/StandManager/Components/Pages/Management/Mail_Utenti_Import.razor b/StandManager/Components/Pages/Management/Mail_Utenti_Import.razor new file mode 100644 index 0000000..97d98b1 --- /dev/null +++ b/StandManager/Components/Pages/Management/Mail_Utenti_Import.razor @@ -0,0 +1,94 @@ +@using System.Globalization +@using System.IO +@using Microsoft.EntityFrameworkCore +@using StandManager.Model +@attribute [Authorize] + +@rendermode InteractiveServer + +@inject AuthenticationStateProvider auth + + + + + +@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(); + + 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; } + } +} \ No newline at end of file diff --git a/StandManager/Components/Pages/Management/Utenti.razor b/StandManager/Components/Pages/Management/Utenti.razor index 63043f7..eb8fa9c 100644 --- a/StandManager/Components/Pages/Management/Utenti.razor +++ b/StandManager/Components/Pages/Management/Utenti.razor @@ -20,6 +20,9 @@
+ + + Nuovo utente @@ -57,6 +60,7 @@ @code { IQueryable utenti; RadzenDataGrid userGrid; + private Ruolo? ruolo; /// /// 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("Importazione mail per utenti", new Dictionary() { { "args", args } }); + } + catch (Exception ex) + { + var er = ex.Message; + await _dialogService.Alert("Si è verificato un errore durante l'importazione del file.", "Errore"); + } + } } diff --git a/StandManager/Components/Pages/RegistrazioneInFiera.razor b/StandManager/Components/Pages/RegistrazioneInFiera.razor index e36964b..b9db8a2 100644 --- a/StandManager/Components/Pages/RegistrazioneInFiera.razor +++ b/StandManager/Components/Pages/RegistrazioneInFiera.razor @@ -13,18 +13,6 @@
- @* @if (showCodiceCliente) - { -
-
-
- - - -
-
-
- } *@ @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(); } } \ No newline at end of file diff --git a/StandManager/Components/Pages/RegistrazioneSocial.razor b/StandManager/Components/Pages/RegistrazioneSocial.razor index c9abb89..4414084 100644 --- a/StandManager/Components/Pages/RegistrazioneSocial.razor +++ b/StandManager/Components/Pages/RegistrazioneSocial.razor @@ -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()