Update modelli x recupero dati BOM

This commit is contained in:
Samuele Locatelli
2025-08-07 17:23:31 +02:00
parent c2f2262b94
commit 7e76014bd5
4 changed files with 72 additions and 33 deletions
+3 -3
View File
@@ -9,10 +9,10 @@ namespace EgwCoreLib.Lux.Core.RestPayload
public class BomDTO
{
public string UID { get; set; } = "";
//public string UID { get; set; } = "";
public string Customer { get; set; } = "";
//public string Customer { get; set; } = "";
public List<BomRowDTO> ItemList { get; set; } = new List<BomRowDTO>();
public List<BomItemDTO> ItemList { get; set; } = new List<BomItemDTO>();
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwCoreLib.Lux.Core.RestPayload
{
public class BomItemDTO
{
public string ClassCode { get; set; } = "";
public string DescriptionCode { get; set; } = "";
public string ItemCode { get; set; } = "";
public double Qty { get; set; } = 0;
public int ItemQty { get; set; } = 0;
}
}
@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwCoreLib.Lux.Core.RestPayload
{
public class BomRowDTO
{
public string BR_UID { get; set; } = "";
public int index { get; set; } = 0;
public string ItemID { get; set; } = "";
public string Name { get; set; } = "";
public string Description { get; set; } = "";
public double PriceUM { get; set; } = 0;
public double Qty { get; set; } = 0;
[NotMapped]
public double PriceTot
{
get => PriceUM * Qty;
}
}
}
@@ -1,4 +1,5 @@
using EgwCoreLib.Lux.Data.DbModel;
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using NLog;
@@ -146,6 +147,55 @@ namespace EgwCoreLib.Lux.Data.Controllers
return answ; ;
}
public bool ItemUpsertFromBom(List<BomItemDTO> bomList)
{
bool answ = false;
//using (DataLayerContext dbCtx = new DataLayerContext(configuration))
using (DataLayerContext dbCtx = new DataLayerContext())
{
try
{
// ciclo x ogni elemento della BOM, cercando x gruppo e ExtItemCode
foreach (var item in bomList)
{
var currRec = dbCtx
.DbSetItem
.Where(x => x.CodGroup == item.ClassCode && x.ExtItemCode == item.ItemCode)
.FirstOrDefault();
// se nullo --> lo devo inserire!!!
if (currRec == null)
{
ItemModel newRec = new ItemModel()
{
CodGroup = item.ClassCode,
IsService = false,
// da calcolare meglio x gruppo
ItemCode = 0,
ExtItemCode = item.ItemCode,
SupplCode = "BOM ITEM",
Description = $"BOM | {item.ClassCode} | {item.ItemCode}",
Cost = 0,
Margin = 0,
BomGen = true,
QtyMin = 0,
QtyMax = 0,
UM = "#"
};
dbCtx.DbSetItem.Add(newRec);
}
}
// salvo...
dbCtx.SaveChanges();
}
catch (Exception exc)
{
Log.Error($"Eccezione durante ItemUpsertFromBom{Environment.NewLine}{exc}");
}
}
return answ; ;
}
/// <summary>
/// Elenco completo offerte da DB
/// </summary>