49 lines
1.0 KiB
C#
49 lines
1.0 KiB
C#
using Entidades;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Modelo
|
|
{
|
|
public sealed class RepositorioCategoria : IRepositorio<Categoria>
|
|
{
|
|
private Context context;
|
|
|
|
public RepositorioCategoria(Context context)
|
|
{
|
|
this.context = 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;
|
|
}
|
|
}
|
|
}
|
|
}
|