ComuneIstat

This commit is contained in:
2025-12-19 10:38:51 +01:00
parent 39246b5d16
commit 1f87913904
15 changed files with 2379 additions and 36 deletions

Binary file not shown.

View File

@ -0,0 +1,13 @@
using StandManager.Domain.Entita.Base;
namespace StandManager.Domain.Entita;
public class ComuneIstat : EntitaBase
{
public string Istat { get; set; }
public string Comune { get; set; }
public string Regione { get; set; }
public string Provincia { get; set; }
public string Prefisso { get; set; }
public string CodFisco { get; set; }
}

View File

@ -24,6 +24,8 @@ public class Utente : EntitaBase
[ForeignKey(nameof(Capoarea))]
public Guid? CapoareaId { get; set; }
public Utente Capoarea { get; set; }
public bool IsCapoarea { get; set; }
public string Info => $"{Nome} {Cognome}";
public override string ToString()
{

View File

@ -12,6 +12,7 @@ public class StandManagerDbContext : OAServiceContext
public DbSet<Cliente> Cliente { get; set; }
public DbSet<ComuneIstat> ComuneIstat { get; set; }
public DbSet<Destinazione> Destinazione { get; set; }
public DbSet<Evento> Evento { get; set; }
public DbSet<InvitoEvento> InvitoEvento { get; set; }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StandManager.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class UtenteECapoarea : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsCapoarea",
table: "Utente",
type: "bit",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsCapoarea",
table: "Utente");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StandManager.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class ComuneIstat : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ComuneIstat",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Istat = table.Column<string>(type: "nvarchar(max)", nullable: false),
Comune = table.Column<string>(type: "nvarchar(max)", nullable: false),
Regione = table.Column<string>(type: "nvarchar(max)", nullable: false),
Provincia = table.Column<string>(type: "nvarchar(max)", nullable: false),
Prefisso = table.Column<string>(type: "nvarchar(max)", nullable: false),
CodFisco = table.Column<string>(type: "nvarchar(max)", nullable: false),
DataCreazione = table.Column<DateTime>(type: "datetime2", nullable: false),
DataModifica = table.Column<DateTime>(type: "datetime2", nullable: true),
Eliminato = table.Column<bool>(type: "bit", nullable: false),
IdUtenteCreazione = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IdUtenteModifica = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ComuneIstat", x => x.Id);
table.ForeignKey(
name: "FK_ComuneIstat_Utente_IdUtenteCreazione",
column: x => x.IdUtenteCreazione,
principalTable: "Utente",
principalColumn: "Id");
table.ForeignKey(
name: "FK_ComuneIstat_Utente_IdUtenteModifica",
column: x => x.IdUtenteModifica,
principalTable: "Utente",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_ComuneIstat_IdUtenteCreazione",
table: "ComuneIstat",
column: "IdUtenteCreazione");
migrationBuilder.CreateIndex(
name: "IX_ComuneIstat_IdUtenteModifica",
table: "ComuneIstat",
column: "IdUtenteModifica");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ComuneIstat");
}
}
}

View File

@ -102,6 +102,60 @@ namespace StandManager.Infrastructure.Migrations
b.ToTable("Cliente");
});
modelBuilder.Entity("StandManager.Domain.Entita.ComuneIstat", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CodFisco")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Comune")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DataCreazione")
.HasColumnType("datetime2");
b.Property<DateTime?>("DataModifica")
.HasColumnType("datetime2");
b.Property<bool>("Eliminato")
.HasColumnType("bit");
b.Property<Guid?>("IdUtenteCreazione")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("IdUtenteModifica")
.HasColumnType("uniqueidentifier");
b.Property<string>("Istat")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Prefisso")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Provincia")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Regione")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("IdUtenteCreazione");
b.HasIndex("IdUtenteModifica");
b.ToTable("ComuneIstat");
});
modelBuilder.Entity("StandManager.Domain.Entita.Destinazione", b =>
{
b.Property<Guid>("Id")
@ -670,6 +724,9 @@ namespace StandManager.Infrastructure.Migrations
b.Property<Guid?>("IdUtenteModifica")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsCapoarea")
.HasColumnType("bit");
b.Property<string>("Nome")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -731,6 +788,21 @@ namespace StandManager.Infrastructure.Migrations
b.Navigation("UtenteModifica");
});
modelBuilder.Entity("StandManager.Domain.Entita.ComuneIstat", b =>
{
b.HasOne("StandManager.Domain.Entita.Utente", "UtenteCreazione")
.WithMany()
.HasForeignKey("IdUtenteCreazione");
b.HasOne("StandManager.Domain.Entita.Utente", "UtenteModifica")
.WithMany()
.HasForeignKey("IdUtenteModifica");
b.Navigation("UtenteCreazione");
b.Navigation("UtenteModifica");
});
modelBuilder.Entity("StandManager.Domain.Entita.Destinazione", b =>
{
b.HasOne("StandManager.Domain.Entita.Utente", "Agente")

View File

@ -5,5 +5,5 @@ namespace StandManager.Service.Interfaces;
public interface IUtenteService : ITService<Utente>
{
Task<List<Utente>> ListaCapoarea();
}

View File

@ -1,3 +1,4 @@
using Microsoft.EntityFrameworkCore;
using OAService.Service.Repository;
using OAService.Service.Servizi.Implementazioni;
using StandManager.Domain.Entita;
@ -14,4 +15,13 @@ public class UtenteService : TService<Utente>, IUtenteService
{
_unitOfWork = unitOfWork;
}
public async Task<List<Utente>> ListaCapoarea()
{
return (await _unitOfWork.UtenteRepository.RicercaQueryable(x => x.IsCapoarea, skip:0, take:0)).ToList();
/*return (await _unitOfWork.UtenteRepository.RicercaQueryable(x =>
x.Ruolo.Permessi.Any(y => y.Feature.Type == FeatureType.Capoarea || y.Feature.Type == FeatureType.AdminGlobal),
includi:x => x.Include(y => y.Ruolo).ThenInclude(z => z.Permessi).ThenInclude(u => u.Feature),
skip: 0, take: 0)).ToList();*/
}
}

View File

@ -37,10 +37,11 @@
AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
Data="@clienti" LogicalFilterOperator="LogicalFilterOperator.Or" SelectionMode="DataGridSelectionMode.Single">
<Columns>
<RadzenDataGridColumn Property="@nameof(ClienteViewModel.Id)" Filterable="false" Title="ID" Width="200px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn Property="@nameof(ClienteViewModel.RagioneSociale)" Title="Ragione sociale" Width="250px" />
<RadzenDataGridColumn Property="@nameof(ClienteViewModel.PartitaIva)" Title="Partita IVA" Width="250px" />
<RadzenDataGridColumn Property="@nameof(ClienteViewModel.NomeAgente)" Title="Agente" Width="250px" />
<RadzenDataGridColumn Property="@nameof(Cliente.Id)" Filterable="false" Title="ID" Width="200px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn Property="@nameof(Cliente.RagioneSociale)" Title="Ragione sociale" Width="250px" />
<RadzenDataGridColumn Property="@nameof(Cliente.PartitaIva)" Title="Partita IVA" Width="250px" />
<RadzenDataGridColumn Property="Agente.Info" Title="Agente" Width="250px" />
<RadzenDataGridColumn Property="Capoarea.Info" Title="Capoarea" Width="250px" />
<RadzenDataGridColumn Context="cliente" Filterable="false" Sortable="false" TextAlign="TextAlign.Right" Width="250px">
<Template Context="cliente">
@ -59,8 +60,8 @@
</div>
@code {
List<ClienteViewModel> clienti;
RadzenDataGrid<ClienteViewModel> clientiGrid;
List<Cliente> clienti;
RadzenDataGrid<Cliente> clientiGrid;
/// <summary>
/// Carica lelenco dei clienti non eliminati, includendo lagente,
@ -72,9 +73,9 @@
clienti = (await _managerService.ClienteService.RicercaQueryable(
x => x.Eliminato == false,
includi: x => x.Include(y => y.Agente),
includi: x => x.Include(y => y.Agente).Include(y => y.Capoarea),
ordinamento: x => x.OrderBy(y => y.RagioneSociale)))
.Select(x => (ClienteViewModel)x).ToList();
.ToList();
}
/// <summary>
@ -97,7 +98,7 @@
{
await _managerService.ClienteService.Elimina(cliente.Id, await MembershipUtils.GetUserId(auth));
clienti = (await _managerService.ClienteService.RicercaQueryable(x => x.Eliminato == false, includi: x => x.Include(y => y.Agente)))
.Select(x => (ClienteViewModel)x).ToList();
.ToList();
}
}

View File

@ -38,6 +38,30 @@
foreach (var row in usedRange.RowsUsed().Skip(1))
rows.Add(new ClienteExcelViewModel(row));
var codiciAgente = rows.Select(r => new { CodiceAgente = r.Agente, Nome = r.DescrizioneAgente, Capoarea = r.CapoArea }).Distinct().ToList();
var codiciCapoarea = rows.Select(r => new { CodiceCapoarea = r.CapoArea, Nome = r.DescrizioneCapoArea }).Distinct().ToList();
var capoareaList = await _managerService.UtenteService.ListaCapoarea();
foreach (var fileCapoarea in codiciCapoarea)
{
var capoarea = await _managerService.UtenteService.RicercaPer(x => x.CodiceAgente == fileCapoarea.CodiceCapoarea);
if ((capoarea?.Id ?? new Guid()) != Guid.Empty)
continue;
capoarea = await mapCapoArea(new Utente(), fileCapoarea.CodiceCapoarea, fileCapoarea.Nome);
await _managerService.UtenteService.Salva(capoarea, idClaim);
capoareaList.Add(capoarea);
}
foreach (var fileAgente in codiciAgente)
{
var agente = await _managerService.UtenteService.RicercaPer(x => x.CodiceAgente == fileAgente.CodiceAgente);
if ((agente?.Id ?? new Guid()) != Guid.Empty)
continue;
var capoarea = capoareaList.FirstOrDefault(x => x.CodiceAgente == fileAgente.Capoarea);
agente = await mapAgente(new Utente(), fileAgente.CodiceAgente, fileAgente.Nome, capoarea.Id);
await _managerService.UtenteService.Salva(agente, idClaim);
}
var ragioniSociali = rows.Select(r => new { Rid = r.CodCli, RagioneSociale = r.RagSocCliente }).Distinct().ToList();
clientiTotali = ragioniSociali.Count;
counterLabel = " di " + clientiTotali;
@ -48,10 +72,14 @@
var clienteDb = await _managerService.ClienteService.RicercaPer(
x => x.Rid == cliente.Rid && x.Eliminato == false,
includi: x => x.Include(i => i.Destinazioni),
includi: x => x.Include(i => i.Destinazioni).Include(y => y.Agente).Include(z => z.Capoarea),
solaLettura: false) ?? new Cliente();
clienteDb = await mapCliente(clienteDb, righeCliente);
clienteDb = await mapCliente(clienteDb, righeCliente, capoareaList, idClaim);
var codiceCapoarea = righeCliente.FirstOrDefault().CapoArea;
var codiceAgente = righeCliente.FirstOrDefault().Agente;
clienteDb.CapoareaId = (await _managerService.UtenteService.RicercaPer(x => x.CodiceAgente == codiceCapoarea))?.Id;
clienteDb.AgenteId = (await _managerService.UtenteService.RicercaPer(x => x.CodiceAgente == codiceAgente))?.Id;
await _managerService.ClienteService.Salva(clienteDb, idClaim);
counter += 1;
StateHasChanged();
@ -61,25 +89,18 @@
_dialogService.Close();
}
private async Task<Cliente> mapCliente(Cliente model, List<ClienteExcelViewModel> rows)
private async Task<Cliente> mapCliente(Cliente model, List<ClienteExcelViewModel> rows, List<Utente> capoareaList, Guid idClaim)
{
var idClaim = await MembershipUtils.GetUserId(auth);
var firstRow = rows.First();
model.Rid = firstRow.CodCli;
model.RagioneSociale = firstRow.RagSocCliente;
model.PartitaIva = firstRow.PartitaIva;
var capoArea = await _managerService.UtenteService.RicercaPer(filtro: x => x.CodiceAgente == firstRow.CapoArea && x.Eliminato == false, solaLettura: false) ?? new Utente();
capoArea = await mapCapoArea(capoArea, firstRow);
if (capoArea.Id == Guid.Empty) capoArea.Password = "";
var savedCapoArea = await _managerService.UtenteService.Salva(capoArea, idClaim);
model.CapoareaId = savedCapoArea.Id;
var agente = await _managerService.UtenteService.RicercaPer(filtro: x => x.CodiceAgente == firstRow.Agente && x.Eliminato == false, solaLettura: false) ?? new Utente();
/*var agente = await _managerService.UtenteService.RicercaPer(filtro: x => x.CodiceAgente == firstRow.Agente && x.Eliminato == false, solaLettura: false) ?? new Utente();
agente = await mapAgente(agente, firstRow, model.CapoareaId);
if (agente.Id == Guid.Empty) agente.Password = "";
var savedAgente = await _managerService.UtenteService.Salva(agente, idClaim);
model.AgenteId = savedAgente.Id;
model.AgenteId = savedAgente.Id;*/
// TODO: Problema nel salvataggio delle destinazioni
model.Destinazioni ??= new();
@ -111,25 +132,28 @@
return model;
}
private async Task<Utente> mapCapoArea(Utente model, ClienteExcelViewModel row)
private async Task<Utente> mapCapoArea(Utente model, string codice, string nome)
{
model.Username = row.DescrizioneCapoArea;
model.CodiceAgente = row.CapoArea;
model.Nome = row.DescrizioneCapoArea;
model.Cognome = "";
model.Email = "";
model.Username = nome;
model.CodiceAgente = codice;
model.Nome = nome;
model.Cognome = string.Empty;
model.Email = string.Empty;
model.Password = string.Empty;
model.IsCapoarea = true;
return model;
}
private async Task<Utente> mapAgente(Utente model, ClienteExcelViewModel row, Guid? capoareaId)
private async Task<Utente> mapAgente(Utente model, string codice, string nome, Guid? capoareaId)
{
model.Username = row.DescrizioneAgente;
model.CodiceAgente = row.Agente;
model.Nome = row.DescrizioneAgente;
model.Username = nome;
model.CodiceAgente = codice;
model.Nome = nome;
model.Cognome = "";
model.Email = "";
model.CapoareaId = capoareaId;
model.Password = string.Empty;
/*model.CapoareaId = capoareaId;*/
return model;
}

View File

@ -17,6 +17,7 @@ public class ClienteViewModel
public string EmailInvito { get; set; }
public string NumeroTelefono { get; set; }
public string NomeAgente { get; set; }
public string NomeCapoarea { get; set; }
public Guid? AgenteId { get; set; }
public UtenteViewModel Agente { get; set; }
public List<DestinazioneViewModel> Destinazioni { get; set; }
@ -35,6 +36,7 @@ public class ClienteViewModel
: new ClienteViewModel()
{
NomeAgente = model.Agente?.Nome.ToString(),
NomeCapoarea = model.Capoarea?.Nome.ToString(),
Agente = model.Agente,
AgenteId = model.AgenteId,
Cap = model.Cap,