a ver si no me olcideo de commitear otra vez
This commit is contained in:
36
Modelo/RepositorioBase.cs
Normal file
36
Modelo/RepositorioBase.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
public abstract class RepositorioBase<T> where T : class, new()
|
||||
{
|
||||
private AlquilaFacilContext Context { get; set; } = new AlquilaFacilContext();
|
||||
|
||||
public void Add(T t){
|
||||
Context.Add(t);
|
||||
}
|
||||
public void Mod(T t){
|
||||
Context.Update(t);
|
||||
}
|
||||
public void Del(T t){
|
||||
|
||||
Context.Remove(t);
|
||||
}
|
||||
|
||||
public bool Guardar(){
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
Context.SaveChanges();
|
||||
Context.Dispose();
|
||||
Context = new AlquilaFacilContext();
|
||||
ret = true;
|
||||
} catch (DbUpdateException ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user