Feat: primera iteracion de los repositorios hecha
Signed-off-by fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
namespace Modelo
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
20
Modelo/IRepositorio.cs
Normal file
20
Modelo/IRepositorio.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
75
Modelo/RepositorioProductos.cs
Normal file
75
Modelo/RepositorioProductos.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user