Feat: primera iteracion de los repositorios hecha

Signed-off-by fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
2024-02-23 23:35:00 -03:00
parent 619b6c5e04
commit 4e2e723ea4
6 changed files with 110 additions and 9 deletions

View File

@@ -1,7 +0,0 @@
namespace Modelo
{
public class Class1
{
}
}

20
Modelo/IRepositorio.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
namespace Modelo
{
public interface IRepositorio<T>
{
private List<T> almacen;
// Añade objetos al almacen
public bool Add(T t);
// Modifica objetos del almacen
public bool Mod(T t);
// Elimina objetos del almacen
public bool Del(T t);
}
}

View File

@@ -0,0 +1,75 @@
namespace Modelo
{
public class RepositorioProductos : IRepositorio<Producto>
{
//Contructor Privado
private RepositorioProductos()
{
almacen = new List<Producto>;
}
// Singleton
private static RepositorioProductos instancia;
public static RepositorioProductos Instancia
{
get
{
if (instancia == null) instancia = new RepositorioProductos();
return instancia;
}
}
public bool Add(Producto t)
{
bool ret;
try
{
almacen.add(t);
ret = true;
}
catch (Exception e)
{
throw;
}
return ret;
}
public bool Mod(Producto t)
{
bool ret;
try
{
var AModificar = almacen.Find(x => x.Id == t.Id);
AModificar = t;
ret = true;
}
catch (Exception e)
{
throw;
}
return ret;
}
public bool Del(Producto t)
{
bool ret;
try
{
var AEliminar = almacen.Find(x => x.Id == t.Id);
almacen.remove(AEliminar);
ret = true;
}
catch (Exception e)
{
throw;
}
return ret;
}
}
}