109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
using Entidades;
|
|
|
|
namespace Modelo
|
|
{
|
|
public sealed class RepositorioLote : RepositorioBase<Lote, RepositorioLote>
|
|
{
|
|
|
|
override public bool Add(Lote t)
|
|
{
|
|
bool ret = false;
|
|
|
|
try
|
|
{
|
|
almacen.Add(t);
|
|
ret = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public bool Add(Remito rem)
|
|
{
|
|
if (rem.MostrarLotes().Count <= 0) return true;
|
|
var ret = false;
|
|
try
|
|
{
|
|
foreach (var detalle in rem.MostrarLotes())
|
|
{
|
|
ret = Add(detalle);
|
|
}
|
|
}catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
override public bool Mod(Lote t)
|
|
{
|
|
bool ret = false;
|
|
|
|
try
|
|
{
|
|
var loteAModificar = almacen.FindIndex(x => x.Id == t.Id);
|
|
if (loteAModificar > -1)
|
|
{
|
|
almacen[loteAModificar] = t;
|
|
ret = true;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
override public bool Del(Lote t)
|
|
{
|
|
bool ret = false;
|
|
|
|
try
|
|
{
|
|
var loteAEliminar = almacen.Find(x => x.Id == t.Id);
|
|
if (loteAEliminar != null)
|
|
{
|
|
loteAEliminar.Habilitado = false;
|
|
ret = true;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
public bool DisminuirStock(DetalleFactura detalleFactura)
|
|
{
|
|
bool ret = false; int cantidad = detalleFactura.Cantidad;
|
|
while (cantidad > 0)
|
|
{
|
|
var elementoAdisminuir = almacen.Where(x=> x.Habilitado == true)
|
|
.First(x => x.Producto.Id == detalleFactura.Producto.Id);
|
|
|
|
cantidad -= elementoAdisminuir.Cantidad;
|
|
|
|
if (cantidad >= 0)
|
|
{
|
|
elementoAdisminuir.Cantidad = 0;
|
|
elementoAdisminuir.Habilitado = false;
|
|
}
|
|
else
|
|
{
|
|
elementoAdisminuir.Cantidad = -cantidad;
|
|
ret = true;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
}
|
|
}
|