empezé a hacer cosas con el dbcontext, termine la clase de repositorio y añadi/implemente los skeleton de varios repositorios
This commit is contained in:
@@ -1,48 +1,46 @@
|
||||
using System.Transactions;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Transactions;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo
|
||||
{
|
||||
public sealed class RepositorioCategoria : IRepositorio<Categoria>
|
||||
public sealed class RepositorioCategoria : Repositorio<Categoria>
|
||||
{
|
||||
private Context context;
|
||||
|
||||
public RepositorioCategoria(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override Categoria ObtenerPorId(int Tid)
|
||||
public IEnumerable<Categoria> Listar()
|
||||
{
|
||||
return context.Categorias.Find(Tid);
|
||||
return context.Categorias.ToList();
|
||||
}
|
||||
|
||||
public override void Add(Categoria t)
|
||||
public Categoria ObtenerPorId(int Tid)
|
||||
{
|
||||
Categoria cat = context.Categorias.Find(Tid);
|
||||
return cat ?? new Categoria();
|
||||
}
|
||||
|
||||
public void Add(Categoria t)
|
||||
{
|
||||
context.Categorias.Add(t);
|
||||
}
|
||||
|
||||
public override void Del(Categoria t)
|
||||
public void Del(Categoria t)
|
||||
{
|
||||
Categoria? cat = context.Categorias.Find(t.Id);
|
||||
Categoria cat = context.Categorias.Find(t.Id);
|
||||
if (cat == null) return;
|
||||
context.Categorias.Remove(cat);
|
||||
}
|
||||
|
||||
public override void Mod(Categoria t)
|
||||
public void Mod(Categoria t)
|
||||
{
|
||||
context.Entry(t).State = EntityState.Modified;
|
||||
context.Categorias.Update(t);
|
||||
}
|
||||
|
||||
public override void Guardar()
|
||||
{
|
||||
try
|
||||
{
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user