diff --git a/Controladora/ControladoraLotes.cs b/Controladora/ControladoraLotes.cs index c799625..f4f253f 100644 --- a/Controladora/ControladoraLotes.cs +++ b/Controladora/ControladoraLotes.cs @@ -17,16 +17,7 @@ namespace Controladora { repositorioLotes = new(new Context()); } - - public string AltaStock(Remito t) - { - if (t == null) return "Esta Mal Cargado"; - - repositorioLotes.Add(t); - return repositorioLotes.Guardar() ? - "Se Cargo Correctamente" : - "Fallo la Carga"; - } + public string DisminuirStock(ReadOnlyCollection detalleFactura) { var ret = false; diff --git a/Controladora/ControladoraRemito.cs b/Controladora/ControladoraRemito.cs index 0a23b2b..045b3c0 100644 --- a/Controladora/ControladoraRemito.cs +++ b/Controladora/ControladoraRemito.cs @@ -26,9 +26,8 @@ namespace Controladora orden.Entregado = true; var retMarcarOrdenEntregada = ControladoraOrdenDeCompras.Instance.Modificar(orden); + repositorioRemito.Add(t); - ControladoraLotes.Instance.AltaStock(t); - return (repositorioRemito.Guardar()) ? diff --git a/Entidades/Lote.cs b/Entidades/Lote.cs index a8ce30f..e56e288 100644 --- a/Entidades/Lote.cs +++ b/Entidades/Lote.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Entidades { - public class Lote: Detalle + public class Lote : Detalle, ICloneable { public int IdRemito { get; set; } public DateTime Fecha { get; set; } @@ -17,6 +17,26 @@ namespace Entidades return Producto.Nombre; } } + + public Lote() { } + + /// ICLONEABLE IMPLEMENTATION + /// + /// ICLONEABLE IMPLEMENTATION + private Lote(Lote lote) + { + Id = lote.Id; + Cantidad = lote.Cantidad; + + IdRemito = lote.IdRemito; + Fecha = lote.Fecha; + Habilitado = lote.Habilitado; + + } + public object Clone() + { + return new Lote(this); + } } } diff --git a/Modelo/RepositorioRemito.cs b/Modelo/RepositorioRemito.cs index 07cfa9d..f82cee3 100644 --- a/Modelo/RepositorioRemito.cs +++ b/Modelo/RepositorioRemito.cs @@ -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(); + + + 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);