ComuneIstat
This commit is contained in:
@ -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 l’elenco dei clienti non eliminati, includendo l’agente,
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -38,20 +38,48 @@
|
||||
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;
|
||||
|
||||
|
||||
foreach (var cliente in ragioniSociali)
|
||||
{
|
||||
var righeCliente = rows.Where(r => r.CodCli == cliente.Rid).ToList();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user