This repository has been archived on 2024-08-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Final_OOP/Modelo/RepositorioFactura.cs

82 lines
2.1 KiB
C#

using System.Collections.ObjectModel;
using Entidades;
namespace Modelo
{
public sealed class RepositorioFactura : RepositorioBase<Factura, RepositorioFactura>
{
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();
}
}
}