Rimozione metodi inutilizzati in repository x updateCost, oltretutto antipattern

This commit is contained in:
Samuele Locatelli
2026-03-23 18:21:11 +01:00
parent 8c957edad8
commit c5d3ee3504
11 changed files with 13 additions and 137 deletions
@@ -31,7 +31,6 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
Task<bool> UpdateAsync(OfferModel entity);
Task<bool> UpdateCostAsync(int offerId);
#endregion Public Methods
}
@@ -29,8 +29,6 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
Task<bool> UpdateAsync(OrderModel entity);
Task<bool> UpdateCostAsync(int OrderID);
#endregion Public Methods
}
}
@@ -1,9 +1,6 @@
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel.Items;
using EgwCoreLib.Lux.Data.DbModel.Items;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using EgwCoreLib.Lux.Data.Domains;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using static EgwCoreLib.Lux.Core.Enums;
namespace EgwCoreLib.Lux.Data.Repository.Sales
@@ -267,66 +264,6 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
return await dbCtx.SaveChangesAsync() > 0;
}
public async Task<bool> UpdateCostAsync(int OfferID)
{
await using var dbCtx = await CreateContextAsync();
// recupero righe offerta...
var offRowList = await dbCtx
.DbSetOfferRow
.Where(x => x.OfferID == OfferID)
.ToListAsync();
// If no rows found, nothing to update
if (offRowList.Count == 0) return false;
// recupero l'elenco degli itemGroup gestiti
var itemGroupList = await dbCtx
.DbSetItemGroup
.ToListAsync();
// recupero il subset item da BOM / BomAlt...
var bomGenList = await dbCtx
.DbSetItem
.Where(x => (x.ItemType == Core.Enums.ItemClassType.Bom || x.ItemType == Core.Enums.ItemClassType.BomAlt))
.ToListAsync();
// ciclo!
foreach (var currRec in offRowList)
{
// se contiene qualcosa x BOM...
if (!string.IsNullOrEmpty(currRec.ItemBOM) && currRec.ItemBOM.Length > 2)
{
// deserializzo
var bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(currRec.ItemBOM);
// se ho trovato elementi...
if (bomList != null)
{
// calcolo il NUOVO costo e lo aggiorno...
double totCost = 0;
double totPrice = 0;
int totItemQty = 0;
int numGroupOk = 0;
int numItemOk = 0;
int numElems = bomList.Count;
// validazione e completamento BOM
BomCalculator.Validate(itemGroupList, bomGenList, ref bomList, null, ref totCost, ref totPrice, ref totItemQty, ref numGroupOk, ref numItemOk);
// salvo BOM...
string itemBom = JsonConvert.SerializeObject(bomList);
currRec.ItemBOM = itemBom;
// salvo arrotondato alla 3° decimale
currRec.BomCost = Math.Round(totCost, 3);
currRec.BomPrice = Math.Round(totPrice, 3);
currRec.BomOk = numElems == numGroupOk;
currRec.ItemOk = numElems == numItemOk;
currRec.ProdItemQty = totItemQty;
dbCtx.Entry(currRec).State = EntityState.Modified;
}
}
}
return await dbCtx.SaveChangesAsync() > 0;
}
#endregion Public Methods
}
@@ -1,10 +1,7 @@
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel.Items;
using EgwCoreLib.Lux.Data.DbModel.Items;
using EgwCoreLib.Lux.Data.DbModel.Production;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using EgwCoreLib.Lux.Data.Domains;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using static EgwCoreLib.Lux.Core.Enums;
namespace EgwCoreLib.Lux.Data.Repository.Sales
@@ -283,67 +280,6 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
return await dbCtx.SaveChangesAsync() > 0;
}
public async Task<bool> UpdateCostAsync(int OrderID)
{
await using var dbCtx = await CreateContextAsync();
// recupero righe Orderta...
var offRowList = await dbCtx
.DbSetOrderRow
.Where(x => x.OrderID == OrderID)
.ToListAsync();
// If no rows found, nothing to update
if (offRowList.Count == 0) return false;
// recupero l'elenco degli itemGroup gestiti
var itemGroupList = await dbCtx
.DbSetItemGroup
.ToListAsync();
// recupero il subset item da BOM / BomAlt...
var bomGenList = await dbCtx
.DbSetItem
.Where(x => (x.ItemType == Core.Enums.ItemClassType.Bom || x.ItemType == Core.Enums.ItemClassType.BomAlt))
.ToListAsync();
// ciclo!
foreach (var currRec in offRowList)
{
// se contiene qualcosa x BOM...
if (!string.IsNullOrEmpty(currRec.ItemBOM) && currRec.ItemBOM.Length > 2)
{
// deserializzo
var bomList = JsonConvert.DeserializeObject<List<BomItemDTO>>(currRec.ItemBOM);
// se ho trovato elementi...
if (bomList != null)
{
// calcolo il NUOVO costo e lo aggiorno...
double totCost = 0;
double totPrice = 0;
int totItemQty = 0;
int numGroupOk = 0;
int numItemOk = 0;
int numElems = bomList.Count;
// validazione e completamento BOM
BomCalculator.Validate(itemGroupList, bomGenList, ref bomList, null, ref totCost, ref totPrice, ref totItemQty, ref numGroupOk, ref numItemOk);
// salvo BOM...
string itemBom = JsonConvert.SerializeObject(bomList);
currRec.ItemBOM = itemBom;
// salvo arrotondato alla 3° decimale
currRec.BomCost = Math.Round(totCost, 3);
currRec.BomPrice = Math.Round(totPrice, 3);
currRec.BomOk = numElems == numGroupOk;
currRec.ItemOk = numElems == numItemOk;
currRec.ProdItemQty = totItemQty;
dbCtx.Entry(currRec).State = EntityState.Modified;
}
}
}
return await dbCtx.SaveChangesAsync() > 0;
}
#endregion Public Methods
}
}