Aggiunto ricalcolo anche importo totale offerta

This commit is contained in:
Samuele Locatelli
2025-08-08 16:35:29 +02:00
parent 7fe9357be4
commit a133c7a3cf
5 changed files with 46 additions and 18 deletions
@@ -236,7 +236,7 @@ namespace EgwCoreLib.Lux.Data.Controllers
/// Elenco completo offerte da DB
/// </summary>
/// <returns></returns>
public List<OfferModel> OfferGetAll()
public async Task<List<OfferModel>> OfferGetAll()
{
List<OfferModel> dbResult = new List<OfferModel>();
//using (DataLayerContext dbCtx = new DataLayerContext(configuration))
@@ -244,11 +244,12 @@ namespace EgwCoreLib.Lux.Data.Controllers
{
try
{
dbResult = dbCtx
.DbSetOffer
.Include(c => c.CustomerNav)
.Include(d => d.DealerNav)
.ToList();
dbResult = await dbCtx
.DbSetOffer
.Include(c => c.CustomerNav)
.Include(d => d.DealerNav)
.Include(o => o.OfferRowNav)
.ToListAsync();
}
catch (Exception exc)
{
+23
View File
@@ -83,6 +83,24 @@ namespace EgwCoreLib.Lux.Data.DbModel
/// </summary>
public OfferStates OffertState { get; set; } = OfferStates.Open;
/// <summary>
/// Numero Item compresi
/// </summary>
[NotMapped]
public int NumItems
{
get => OfferRowNav?.Count ?? 0;
}
/// <summary>
/// Imposto totale offerta
/// </summary>
[NotMapped]
public double TotalCost
{
get => OfferRowNav?.Sum(x => x.Cost) ?? 0;
}
#if false
/// <summary>
/// ID Ordine (nullo se non c'è ordine)
@@ -107,5 +125,10 @@ namespace EgwCoreLib.Lux.Data.DbModel
/// </summary>
[ForeignKey("DealerID")]
public virtual DealerModel DealerNav { get; set; } = null!;
/// <summary>
/// Navigazione alle righe offerta
/// </summary>
public virtual ICollection<OfferRowModel> OfferRowNav { get; set; } = new List<OfferRowModel>();
}
}
@@ -150,7 +150,7 @@ namespace EgwCoreLib.Lux.Data.Services
/// Elenco completo offerte da DB
/// </summary>
/// <returns></returns>
public List<OfferModel> OfferGetAll()
public async Task<List<OfferModel>> OfferGetAll()
{
string source = "DB";
Stopwatch sw = new Stopwatch();
@@ -158,7 +158,7 @@ namespace EgwCoreLib.Lux.Data.Services
List<OfferModel>? result = new List<OfferModel>();
// cerco in redis...
string currKey = $"{redisBaseKey}:Offers:ALL";
RedisValue rawData = redisDb.StringGet(currKey);
RedisValue rawData = await redisDb.StringGetAsync(currKey);
//if (!string.IsNullOrEmpty($"{rawData}"))
if (rawData.HasValue)
{
@@ -167,10 +167,10 @@ namespace EgwCoreLib.Lux.Data.Services
}
else
{
result = dbController.OfferGetAll();
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, LongCache);
result = await dbController.OfferGetAll();
// serializzo e salvo con config x evitare loop...
rawData = JsonConvert.SerializeObject(result, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (result == null)
{
+6 -2
View File
@@ -161,8 +161,12 @@ else
{
<td>@item.Description</td>
}
<td class="text-end">...</td>
<td class="text-end">---</td>
<td class="text-end">
@item.NumItems
</td>
<td class="text-end">
@item.TotalCost.ToString("C2")
</td>
</tr>
}
</tbody>
+4 -4
View File
@@ -76,10 +76,10 @@ namespace Lux.UI.Components.Pages
SelRecord = curRec;
}
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
SetupArrows();
ReloadData();
await ReloadData();
UpdateTable();
}
@@ -148,9 +148,9 @@ namespace Lux.UI.Components.Pages
/// <summary>
/// Legge i dati dei record completi
/// </summary>
private void ReloadData()
private async Task ReloadData()
{
AllRecords = DLService.OfferGetAll();
AllRecords = await DLService.OfferGetAll();
totalCount = AllRecords.Count();
}