fix griglia clienti
This commit is contained in:
@ -66,6 +66,14 @@
|
|||||||
<span class="nav-link-title"> Utenti </span>
|
<span class="nav-link-title"> Utenti </span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/management/Clienti">
|
||||||
|
<span class="nav-link-icon d-md-none d-lg-inline-block">
|
||||||
|
<i class="fa-solid fa-address-card"></i>
|
||||||
|
</span>
|
||||||
|
<span class="nav-link-title"> Clienti </span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
187
StandManager/Components/Pages/Management/Clienti.razor
Normal file
187
StandManager/Components/Pages/Management/Clienti.razor
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
@page "/management/clienti"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using StandManager.Domain.Entita
|
||||||
|
@using StandManager.Service.Interfaces
|
||||||
|
@inject IManagerService _managerService
|
||||||
|
|
||||||
|
<h3>Clienti</h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@inject IManagerService _managerService
|
||||||
|
|
||||||
|
<h3>Clienti</h3>
|
||||||
|
|
||||||
|
@*BOZZA NEW VERSION*@
|
||||||
|
@* <RadzenDataGrid TItem="Cliente"
|
||||||
|
@ref="grid"
|
||||||
|
Data="@clienti"
|
||||||
|
AllowFiltering="true"
|
||||||
|
AllowColumnResize="true"
|
||||||
|
AllowAlternatingRows="false"
|
||||||
|
FilterMode="FilterMode.Advanced"
|
||||||
|
AllowSorting="true"
|
||||||
|
PageSize="5"
|
||||||
|
AllowPaging="true"
|
||||||
|
PagerHorizontalAlign="HorizontalAlign.Left"
|
||||||
|
ShowPagingSummary="true"
|
||||||
|
ColumnWidth="300px"
|
||||||
|
LogicalFilterOperator="LogicalFilterOperator.Or"
|
||||||
|
SelectionMode="DataGridSelectionMode.Single"
|
||||||
|
@bind-Value="clienteSelezionato"
|
||||||
|
EditMode="DataGridEditMode.Single">
|
||||||
|
|
||||||
|
<Columns>
|
||||||
|
@* Colonna comandi con toolbar Aggiungi + pulsanti Modifica/Elimina *@
|
||||||
|
@* <RadzenDataGridColumn TItem="Cliente" Context="cliente" Width="200px" Frozen="true">
|
||||||
|
<HeaderTemplate>
|
||||||
|
<RadzenButton Icon="add"
|
||||||
|
Text="Aggiungi"
|
||||||
|
Size="ButtonSize.Small"
|
||||||
|
Click="@AddRow" />
|
||||||
|
</HeaderTemplate>
|
||||||
|
|
||||||
|
<Template Context="cliente">
|
||||||
|
<RadzenButton Icon="edit"
|
||||||
|
ButtonStyle="ButtonStyle.Light"
|
||||||
|
Size="ButtonSize.Small"
|
||||||
|
Click="@(() => EditRow(cliente))" />
|
||||||
|
<RadzenButton Icon="delete"
|
||||||
|
ButtonStyle="ButtonStyle.Danger"
|
||||||
|
Size="ButtonSize.Small"
|
||||||
|
Click="@(() => DeleteRow(cliente))" />
|
||||||
|
</Template>
|
||||||
|
|
||||||
|
<EditTemplate Context="cliente">
|
||||||
|
<RadzenButton Icon="save"
|
||||||
|
ButtonStyle="ButtonStyle.Primary"
|
||||||
|
Size="ButtonSize.Small"
|
||||||
|
Click="@(() => SaveRow(cliente))" />
|
||||||
|
<RadzenButton Icon="cancel"
|
||||||
|
ButtonStyle="ButtonStyle.Light"
|
||||||
|
Size="ButtonSize.Small"
|
||||||
|
Click="@(() => CancelEdit(cliente))" />
|
||||||
|
</EditTemplate>
|
||||||
|
</RadzenDataGridColumn>
|
||||||
|
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Id)" Filterable="false" Title="ID" Width="80px" TextAlign="TextAlign.Center" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.RagioneSociale)" Title="Ragione Sociale" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.PartitaIva)" Title="Partita Iva" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Indirizzo)" Title="Indirizzo" Width="200px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.NumeroTelefono)" Title="Numero di Telefono" Width="120px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Agente)" Title="Agente" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Citta)" Title="Città" Width="160px" />
|
||||||
|
</Columns>
|
||||||
|
</RadzenDataGrid>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
RadzenDataGrid<Cliente>? grid;
|
||||||
|
|
||||||
|
List<Cliente> clienti = new();
|
||||||
|
Cliente? clienteSelezionato;
|
||||||
|
Cliente? clienteInInserimento; // per distinguere "nuovo" da "esistente"
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
// Prima avevi IQueryable<Cliente>. Ora usiamo List<Cliente> per gestire facilmente CRUD in memoria
|
||||||
|
var query = await _managerService.ClienteService.RicercaQueryable(x => x.Eliminato == false);
|
||||||
|
clienti = await query.ToListAsync();
|
||||||
|
|
||||||
|
clienteSelezionato = clienti.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========= COMANDI UI (toolbar + pulsanti riga) ==========
|
||||||
|
|
||||||
|
async Task AddRow()
|
||||||
|
{
|
||||||
|
// crea un nuovo cliente in edit
|
||||||
|
clienteInInserimento = new Cliente();
|
||||||
|
clienti.Insert(0, clienteInInserimento);
|
||||||
|
await grid!.InsertRow(clienteInInserimento);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task EditRow(Cliente cliente)
|
||||||
|
{
|
||||||
|
clienteInInserimento = null; // non è un "nuovo", è edit di esistente
|
||||||
|
await grid!.EditRow(cliente);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task SaveRow(Cliente cliente)
|
||||||
|
{
|
||||||
|
// Chiude la modalità edit a livello UI
|
||||||
|
await grid!.UpdateRow(cliente);
|
||||||
|
|
||||||
|
// Persistenza su DB
|
||||||
|
if (clienteInInserimento == cliente)
|
||||||
|
{
|
||||||
|
// INSERIMENTO
|
||||||
|
// TODO: sostituisci con il tuo metodo reale
|
||||||
|
// await _managerService.ClienteService.Inserisci(cliente);
|
||||||
|
// await _managerService.UnitOfWork.SalvaAsync();
|
||||||
|
|
||||||
|
clienteInInserimento = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// UPDATE
|
||||||
|
// TODO: sostituisci con il tuo metodo reale
|
||||||
|
// await _managerService.ClienteService.Aggiorna(cliente);
|
||||||
|
// await _managerService.UnitOfWork.SalvaAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CancelEdit(Cliente cliente)
|
||||||
|
{
|
||||||
|
if (clienteInInserimento == cliente)
|
||||||
|
{
|
||||||
|
// se annullo l'inserimento, tolgo la riga fittizia
|
||||||
|
clienti.Remove(cliente);
|
||||||
|
clienteInInserimento = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
grid!.CancelEditRow(cliente);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task DeleteRow(Cliente cliente)
|
||||||
|
{
|
||||||
|
// Persistenza su DB
|
||||||
|
// TODO: soft-delete o hard-delete a seconda della tua logica:
|
||||||
|
// cliente.Eliminato = true;
|
||||||
|
// await _managerService.ClienteService.Aggiorna(cliente);
|
||||||
|
// await _managerService.UnitOfWork.SalvaAsync();
|
||||||
|
|
||||||
|
clienti.Remove(cliente);
|
||||||
|
await grid!.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*@
|
||||||
|
|
||||||
|
@*OLD VERSION*@
|
||||||
|
<RadzenDataGrid AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.Advanced" AllowSorting="true" PageSize="5" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
|
||||||
|
Data="@clienti" ColumnWidth="300px" LogicalFilterOperator="LogicalFilterOperator.Or" SelectionMode="DataGridSelectionMode.Single" @bind-Value=@clientiSelected>
|
||||||
|
<Columns>
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Id)" Filterable="false" Title="ID" Frozen="true" Width="80px" TextAlign="TextAlign.Center" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.RagioneSociale)" Title="Ragione Sociale" Frozen="true" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.PartitaIva)" Title="Partita Iva" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Indirizzo)" Title="Indirizzo" Width="200px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.NumeroTelefono)" Title="Numero di Telefono" Width="120px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Agente)" Title="Agente" FormatString="{0:d}" Width="160px" />
|
||||||
|
<RadzenDataGridColumn Property="@nameof(Cliente.Citta)" Title="Città" FormatString="{0:d}" Width="160px" />
|
||||||
|
</Columns>
|
||||||
|
</RadzenDataGrid>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
IQueryable<Cliente> clienti;
|
||||||
|
IList<Cliente> clientiSelected;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
|
||||||
|
clienti = await _managerService.ClienteService.RicercaQueryable(x => x.Eliminato == false);
|
||||||
|
|
||||||
|
clientiSelected = new List<Cliente>() { clienti.FirstOrDefault() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
0
StandManager/Components/Pages/_Imports.razor
Normal file
0
StandManager/Components/Pages/_Imports.razor
Normal file
Reference in New Issue
Block a user