Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created April 28, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/f39d3906e826ee98f39f2c76e7179a1f to your computer and use it in GitHub Desktop.
Save icebeam7/f39d3906e826ee98f39f2c76e7179a1f to your computer and use it in GitHub Desktop.
FaceLoginApp: ServicioBaseDatos.cs
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using FaceLoginApp.Datos;
using FaceLoginApp.Helpers;
using FaceLoginApp.Modelos;
namespace FaceLoginApp.Servicios
{
public class ServicioBaseDatos : IServicioBaseDatos
{
private readonly BaseDatos bd;
public ServicioBaseDatos()
{
bd = new BaseDatos(Constantes.NombreBD);
}
public async Task<Usuario> ObtenerUsuario(string key)
{
try
{
return await bd.Usuarios.FirstOrDefaultAsync(x => x.Key == key);
}
catch (Exception e)
{
return null;
}
}
public async Task<bool> RegistrarUsuario(Usuario dato)
{
try
{
await bd.Usuarios.AddAsync(dato);
await bd.SaveChangesAsync();
return true;
}
catch (Exception e)
{
return false;
}
}
public async Task<bool> ActualizarUsuario(Usuario dato)
{
try
{
bd.Usuarios.Update(dato);
await bd.SaveChangesAsync();
return true;
}
catch (Exception e)
{
var msg = e.Message;
return false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment