43 lines
971 B
C#
43 lines
971 B
C#
using Entidades;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Modelo
|
|
{
|
|
public sealed class RepositorioCategoria : IRepositorio<Categoria>
|
|
{
|
|
private Context context = new Context();
|
|
public override Categoria ObtenerPorId(int Tid)
|
|
{
|
|
return context.Categorias.Find(Tid);
|
|
}
|
|
|
|
public override void Add(Categoria t)
|
|
{
|
|
context.Categorias.Add(t);
|
|
}
|
|
|
|
public override void Del(Categoria t)
|
|
{
|
|
Categoria? cat = context.Categorias.Find(t.Id);
|
|
context.Categorias.Remove(cat);
|
|
}
|
|
|
|
public override void Mod(Categoria t)
|
|
{
|
|
context.Entry(t).State = EntityState.Modified;
|
|
}
|
|
|
|
public override void Guardar()
|
|
{
|
|
try
|
|
{
|
|
context.SaveChanges();
|
|
}
|
|
catch (DbUpdateException)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|