Created
April 28, 2018 14:22
-
-
Save icebeam7/f39d3906e826ee98f39f2c76e7179a1f to your computer and use it in GitHub Desktop.
FaceLoginApp: 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 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