Fix: ahora los remitos guardan bien

This commit is contained in:
fedpo
2024-09-30 17:21:54 +01:00
parent e3fd07a90a
commit c8827a6e2f
4 changed files with 49 additions and 14 deletions

View File

@@ -30,11 +30,36 @@ namespace Modelo
public override void Add(Remito t)
{
t.Lotes = context.Lotes.Where(x => x.IdRemito == t.Id).ToList();
if (t.Lotes == null) return;
t.Proveedor = context.Proveedores.First(x => x.Cuit == t.Proveedor.Cuit);
var listaLotes = new List<Lote>();
foreach (var lote in t.Lotes)
{
listaLotes.Add((Lote)lote.Clone());
listaLotes.Last().Producto = lote.Producto;
}
foreach (var lote in listaLotes)
{
lote.Producto = (lote.Producto.EsPerecedero) ?
context.ProductoPercederos.FirstOrDefault(x => x.Id == lote.Producto.Id) :
context.ProductoNoPercederos.FirstOrDefault(x => x.Id == lote.Producto.Id);
}
t.Lotes = listaLotes;
context.Remitos.Add(t);
}
public override void Del(Remito t)
{
Remito rem = context.Remitos.First(x => x.Id == t.Id);