Hecho Irepositorio y borrado codigo viejo de repositorios. Además configuré entity framework

This commit is contained in:
2024-08-12 16:48:54 -03:00
parent 01d975c47f
commit b7177439ef
75 changed files with 9512 additions and 17769 deletions

View File

@@ -3,79 +3,8 @@ using Entidades;
namespace Modelo
{
public sealed class RepositorioFactura : RepositorioBase<Factura, RepositorioFactura>
public sealed class RepositorioFactura : IRepositorio<Factura>
{
override public bool Add(Factura t)
{
if (ExistePorId(t.Id))
{
throw new InvalidOperationException($"La Factura con el ID {t.Id} ya existe.");
}
if (t.Cliente == null || t.Cliente.Cuit == 0)
{
throw new InvalidOperationException("Debe seleccionar un cliente antes de agregar la factura.");
}
try
{
almacen.Add(t);
return true;
}
catch (Exception ex)
{
// Mejor manejo de excepciones, podrías registrar el error
throw new Exception("Error al agregar la factura.", ex);
}
}
public bool ExistePorId(int id)
{
return almacen.Any(f => f.Id == id);
}
override public bool Mod(Factura t)
{
bool ret = false;
try
{
var facturaAModificar = almacen.FindIndex(x => x.Id == t.Id);
if (facturaAModificar > -1)
{
almacen[facturaAModificar] = t;
ret = true;
}
}
catch (Exception)
{
throw;
}
return ret;
}
override public bool Del(Factura t)
{
bool ret = false;
try
{
var facturaAEliminar = almacen.Find(x => x.Id == t.Id);
if (facturaAEliminar != null)
{
almacen.Remove(facturaAEliminar);
ret = true;
}
}
catch (Exception)
{
throw;
}
return ret;
}
public ReadOnlyCollection<DetalleFactura> MostrarDetalles(Factura factura)
{
return factura.MostrarDetalles();
}
}
}