primeros cambios
This commit is contained in:
@@ -7,11 +7,11 @@ namespace Modelo;
|
||||
public abstract class RepositorioBase<S>
|
||||
where S : new()
|
||||
{
|
||||
protected AlquilaFacilContext Context { get{ return new AlquilaFacilContext();}}
|
||||
protected AlquilaFacilContext Context { get { return new AlquilaFacilContext(); }}
|
||||
private static readonly S instance = new();
|
||||
public static S Singleton { get{return instance;}}
|
||||
public static S Singleton { get { return instance; }}
|
||||
|
||||
public bool Guardar(AlquilaFacilContext context){
|
||||
public bool Guardar(AlquilaFacilContext context) {
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -8,7 +8,9 @@ public class RepositorioInquilinos: RepositorioBase<RepositorioInquilinos> {
|
||||
{
|
||||
FormattableString sqlq =
|
||||
$"""
|
||||
SELECT I.Dni, I.Nombre, I.Apellido FROM Inquilinos
|
||||
SELECT I.Dni, I.Nombre, I.Apellido FROM Clientes I
|
||||
JOIN cliente_Grupos cg on cg.idcliente = I.Dni
|
||||
WHERE cg.idgrupo = 2;
|
||||
""";
|
||||
return Context.Database.SqlQuery<InquilinoDto>(sqlq);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
||||
{
|
||||
public IQueryable<Propiedade> ListarPropiedades(){
|
||||
var con = Context;
|
||||
return con.Propiedades.AsQueryable();
|
||||
}
|
||||
|
||||
public bool AñadirPropiedad(){
|
||||
return false;
|
||||
public bool AñadirPropiedad(Propiedade prop){
|
||||
var con = Context;
|
||||
|
||||
int count = con.Propiedades.Count()+1;
|
||||
|
||||
prop.Id = count;
|
||||
prop.Idestado = 1;
|
||||
con.Propiedades.Add(prop);
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropietario: RepositorioBase<RepositorioPropietario> {
|
||||
public Cliente? ObtenerClientePorEmail(string email){
|
||||
var con = Context;
|
||||
|
||||
Cliente? cli = con.Clientes.FirstOrDefault(c => c.Email == email);
|
||||
return cli;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,9 +7,8 @@ using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
{
|
||||
public bool AltaInquilino(Cliente cli){
|
||||
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
public bool AltaInquilino(Cliente cli) {
|
||||
var con = Context;
|
||||
|
||||
//check por si la cuenta ya existe (puede ser propietario)
|
||||
@@ -34,8 +33,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
|
||||
}
|
||||
|
||||
public bool AltaPropietario(Cliente cli)
|
||||
{
|
||||
public bool AltaPropietario(Cliente cli) {
|
||||
var con = Context;
|
||||
|
||||
//check por si la cuenta ya existe (puede ser propietario)
|
||||
@@ -58,6 +56,16 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool ActualizarPropietario(Cliente cli) {
|
||||
var con = Context;
|
||||
Cliente? cliOld = con.Clientes.Find(cli.Dni);
|
||||
if (cliOld == null) return false;
|
||||
|
||||
cliOld = cli;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool CheckUsuario(LoginDto logindto) {
|
||||
|
||||
string Contraseña = HacerHash(logindto.Contraseña);
|
||||
@@ -71,12 +79,12 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return false;
|
||||
|
||||
}
|
||||
private string HacerHash(string pass){
|
||||
private string HacerHash(string pass) {
|
||||
var buf = SHA256.HashData(Encoding.UTF8.GetBytes(pass));
|
||||
return BitConverter.ToString(buf).Replace("-","");
|
||||
}
|
||||
|
||||
public bool CheckToken(string email, string token){
|
||||
public bool CheckToken(string email, string token) {
|
||||
var usu = Context.Clientes.FirstOrDefault(x => x.Email == email);
|
||||
if (usu == null) return false;
|
||||
|
||||
@@ -87,8 +95,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return usu.Token == token;
|
||||
}
|
||||
|
||||
public void GuardarToken(LoginDto login, string tokenString)
|
||||
{
|
||||
public void GuardarToken(LoginDto login, string tokenString) {
|
||||
var con = Context;
|
||||
var usu = con.Clientes.FirstOrDefault(x => x.Email == login.Email);
|
||||
if (usu == null) return;
|
||||
|
||||
Reference in New Issue
Block a user