cambios nachito a form factura

This commit is contained in:
2024-08-11 18:24:04 -03:00
parent 6f95fd935a
commit e3aec2879e
39 changed files with 847 additions and 70 deletions

View File

@@ -0,0 +1,119 @@
using Entidades;
using Modelo;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Controladora
{
public class ControladoraLotes : Singleton<ControladoraLotes>
{
public string Añadir(Lote t)
{
if (t == null) return "El Lote es nulo, falló la carga";
try
{
bool resultado = RepositorioLote.Instance.Add(t);
return resultado ?
$"El Lote con el ID {t.Id} se cargó correctamente" :
$"Falló la carga del Lote con el ID {t.Id}";
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
return $"Ocurrió un error inesperado: {ex.Message}";
}
}
public string Modificar(Lote t)
{
if (t == null) return "El Lote es nulo, falló la modificación";
try
{
bool resultado = RepositorioLote.Instance.Mod(t);
return resultado ?
$"El Lote con el ID {t.Id} se modificó correctamente" :
$"Falló la modificación del Lote con el ID {t.Id}";
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
return $"Ocurrió un error inesperado: {ex.Message}";
}
}
public string Eliminar(Lote t)
{
if (t == null) return "El Lote es nulo, falló la eliminación";
try
{
bool resultado = RepositorioLote.Instance.Del(t);
return resultado ?
$"El Lote con el ID {t.Id} se eliminó correctamente" :
$"Falló la eliminación del Lote con el ID {t.Id}";
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
return $"Ocurrió un error inesperado: {ex.Message}";
}
}
public string EliminarPorFacturaId(int facturaId)
{
try
{
var lotes = RepositorioLote.Instance.Listar();
var lotesAEliminar = lotes.Where(lote => lote.Id == facturaId).ToList();
foreach (var lote in lotesAEliminar)
{
RepositorioLote.Instance.Del(lote);
}
return lotesAEliminar.Any() ?
$"Los Lotes asociados a la Factura con el ID {facturaId} se eliminaron correctamente" :
$"No se encontraron Lotes asociados a la Factura con el ID {facturaId}";
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
return $"Ocurrió un error inesperado: {ex.Message}";
}
}
public ReadOnlyCollection<Lote> ListarPorFacturaId(int facturaId)
{
try
{
var lotes = RepositorioLote.Instance.Listar();
var lotesPorFactura = lotes.Where(lote => lote.Id == facturaId).ToList();
return new ReadOnlyCollection<Lote>(lotesPorFactura);
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
throw new InvalidOperationException($"Ocurrió un error inesperado: {ex.Message}");
}
}
public ReadOnlyCollection<Lote> Listar()
{
try
{
return RepositorioLote.Instance.Listar();
}
catch (Exception ex)
{
// Captura cualquier excepción no prevista
throw new InvalidOperationException($"Ocurrió un error inesperado: {ex.Message}");
}
}
}
}