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

@@ -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> detalleFactura)
{
var ret = false;

View File

@@ -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()) ?

View File

@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entidades
{
public class Lote: Detalle<Producto>
public class Lote : Detalle<Producto>, ICloneable
{
public int IdRemito { get; set; }
public DateTime Fecha { get; set; }
@@ -17,6 +17,26 @@ namespace Entidades
return Producto.Nombre;
}
}
public Lote() { }
/// ICLONEABLE IMPLEMENTATION
/// <summary>
/// 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);
}
}
}

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);