diff --git a/EgwCoreLib.Lux.Core/RestPayload/BomDTO.cs b/EgwCoreLib.Lux.Core/RestPayload/BomDTO.cs index 5f578ad9..93a7d481 100644 --- a/EgwCoreLib.Lux.Core/RestPayload/BomDTO.cs +++ b/EgwCoreLib.Lux.Core/RestPayload/BomDTO.cs @@ -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 ItemList { get; set; } = new List(); + public List ItemList { get; set; } = new List(); } } diff --git a/EgwCoreLib.Lux.Core/RestPayload/BomItemDTO.cs b/EgwCoreLib.Lux.Core/RestPayload/BomItemDTO.cs new file mode 100644 index 00000000..5c75f6cd --- /dev/null +++ b/EgwCoreLib.Lux.Core/RestPayload/BomItemDTO.cs @@ -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; + } +} diff --git a/EgwCoreLib.Lux.Core/RestPayload/BomRowDTO.cs b/EgwCoreLib.Lux.Core/RestPayload/BomRowDTO.cs deleted file mode 100644 index 62e80872..00000000 --- a/EgwCoreLib.Lux.Core/RestPayload/BomRowDTO.cs +++ /dev/null @@ -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; - } - } -} diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index 5bbf5584..1b9853de 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -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 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; ; + } + /// /// Elenco completo offerte da DB ///