Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SistemaEscolar: ServicioBaseDatos.cs
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using SistemaEscolar.Datos;
namespace SistemaEscolar.Servicios
{
public class ServicioBaseDatos<T> : IServicioBaseDatos<T> where T : class
{
BaseDatos bd;
public ServicioBaseDatos()
{
bd = App.BD;
}
public virtual async Task<List<T>> ObtenerTabla()
{
return await bd.Set<T>().ToListAsync();
}
public virtual async Task<T> BuscarPorId(int id)
{
return await bd.Set<T>().FindAsync(id);
}
public virtual async Task<T> Agregar(T dato)
{
await bd.Set<T>().AddAsync(dato);
await bd.SaveChangesAsync();
return dato;
}
public virtual async Task<T> Actualizar(T dato)
{
bd.Set<T>().Update(dato);
await bd.SaveChangesAsync();
return dato;
}
public virtual async Task<bool> Eliminar(int id)
{
var entity = await BuscarPorId(id);
bd.Set<T>().Remove(entity);
await bd.SaveChangesAsync();
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.