142 lines
4.1 KiB
C#
142 lines
4.1 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Core.Generic;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.Services.Sales;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Lux.UI.Components.Compo.Offer
|
|
{
|
|
/// <summary>
|
|
/// Componente per la gestione delle offerte.
|
|
/// </summary>
|
|
public partial class OfferMan
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Modello dell'offerta corrente (bindato dal genitore).
|
|
/// </summary>
|
|
[Parameter]
|
|
public OfferModel CurrRecord { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Callback invocato a richiesta cancel editing della finestra
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<bool> EC_Cancel { get; set; }
|
|
|
|
/// <summary>
|
|
/// Evento che indica variazione rispetto ai dati originali
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<EditStepDto> EC_Changed { get; set; }
|
|
|
|
/// <summary>
|
|
/// Callback invocato alla richiesta di salvataggio con l'offerta aggiornata.
|
|
/// </summary>
|
|
[Parameter]
|
|
public EventCallback<OfferModel> EC_Updated { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Chiamato automaticamente all'inizializzazione del componente.
|
|
/// </summary>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
setOriginal();
|
|
await ReloadDataAsync();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
setOriginal();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Lista di tutti i clienti caricati.
|
|
/// </summary>
|
|
private List<CustomerModel> CustomersList = new List<CustomerModel>();
|
|
|
|
private List<DealerModel> DealersList = new List<DealerModel>();
|
|
private OfferModel? OrigRecord = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private ICustomerService CService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDealerService DService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private Task DoCancel()
|
|
{
|
|
return EC_Cancel.InvokeAsync(true);
|
|
}
|
|
|
|
private Task DoSave()
|
|
{
|
|
// richiesta update con salvataggio record
|
|
return EC_Updated.InvokeAsync(CurrRecord);
|
|
}
|
|
|
|
private bool HasChanged()
|
|
{
|
|
bool answ = false;
|
|
if (OrigRecord != null && CurrRecord != null)
|
|
{
|
|
if (IsChanged(OrigRecord.CustomerID, CurrRecord.CustomerID))
|
|
return true;
|
|
if (IsChanged(OrigRecord.DealerID, CurrRecord.DealerID))
|
|
return true;
|
|
if (IsChanged(OrigRecord.OffertState, CurrRecord.OffertState))
|
|
return true;
|
|
if (IsChanged(OrigRecord.Inserted, CurrRecord.Inserted))
|
|
return true;
|
|
if (IsChanged(OrigRecord.ValidUntil, CurrRecord.ValidUntil))
|
|
return true;
|
|
if (IsChanged(OrigRecord.Description, CurrRecord.Description))
|
|
return true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica variazione tramite helper
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="original"></param>
|
|
/// <param name="edited"></param>
|
|
/// <returns></returns>
|
|
private bool IsChanged<T>(T original, T edited) => CloneExtensions.IsChanged(original, edited);
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
CustomersList = await CService.GetAllAsync();
|
|
DealersList = await DService.GetAllAsync();
|
|
}
|
|
|
|
private void setOriginal()
|
|
{
|
|
if (CurrRecord != null && OrigRecord == null)
|
|
{
|
|
OrigRecord = CurrRecord.DeepClone();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |