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