login funcional
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
using Entidades;
|
||||
using System.Collections.ObjectModel;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
public abstract class RepositorioBase<T> where T : class, new()
|
||||
{
|
||||
private AlquilaFacilContext Context { get; set; } = new AlquilaFacilContext();
|
||||
protected 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 abstract ReadOnlyCollection<T> Listar();
|
||||
|
||||
public bool Guardar(){
|
||||
bool ret = false;
|
||||
|
||||
37
Modelo/RepositorioUsuarios.cs
Normal file
37
Modelo/RepositorioUsuarios.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
namespace Modelo;
|
||||
|
||||
public class RepositorioUsuarios: RepositorioBase<Usuario>
|
||||
{
|
||||
public static RepositorioUsuarios Singleton = new();
|
||||
public Usuario? CheckUsuario(LoginDto logindto) {
|
||||
|
||||
byte[] Contraseña = HacerHash(logindto.Contrasena);
|
||||
|
||||
bool usu = Context.Inquilinos.Any(x=>x.Email == logindto.Usuario && x.Contrasena == Contraseña);
|
||||
if (usu){
|
||||
return Context.Inquilinos.FirstOrDefault(x=>x.Email == logindto.Usuario);
|
||||
}
|
||||
usu = Context.Propietarios.Any(x=>x.Email == logindto.Usuario && x.Contrasena == Contraseña);
|
||||
if (usu){
|
||||
return Context.Propietarios.FirstOrDefault(x=>x.Email == logindto.Usuario);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override ReadOnlyCollection<Usuario> Listar()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public byte[] HacerHash(string pass){
|
||||
var buf = SHA256.HashData(Encoding.UTF8.GetBytes(pass));
|
||||
return Encoding.UTF8.GetBytes(BitConverter.ToString(buf).Replace("-","").ToLower());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user