Created
May 11, 2018 12:17
-
-
Save icebeam7/e202f49e19dd7a16164f677dd3028571 to your computer and use it in GitHub Desktop.
SistemaEscolar: ServicioBaseDatos.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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