diff --git a/Aspnet/Builder/GaranteBuilder.cs b/Aspnet/Builder/GaranteBuilder.cs new file mode 100644 index 0000000..4c996f4 --- /dev/null +++ b/Aspnet/Builder/GaranteBuilder.cs @@ -0,0 +1,35 @@ +using Entidades; + +namespace AlquilaFacil.Builder; + +public class GaranteBuilder : Builder { + public GaranteBuilder SetNombre(string Nombre) { + data.Nombre = Nombre; + return this; + } + + public GaranteBuilder SetApellido(string Apellido) { + data.Apellido = Apellido; + return this; + } + + public GaranteBuilder SetDni(long Dni) { + data.Dni = Dni; + return this; + } + + public GaranteBuilder SetDomicilio(string Domicilio) { + data.Domicilio = Domicilio; + return this; + } + + public GaranteBuilder SetCelular(string Celular) { + data.Celular = Celular; + return this; + } + + public GaranteBuilder SetDomicilioLaboral(string Domiciliolaboral) { + data.Domiciliolaboral = Domiciliolaboral; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Builder/PrecontratoBuilder.cs b/Aspnet/Builder/PrecontratoBuilder.cs new file mode 100644 index 0000000..a51b1c0 --- /dev/null +++ b/Aspnet/Builder/PrecontratoBuilder.cs @@ -0,0 +1,45 @@ +namespace AlquilaFacil.Builder; + +using System; +using Entidades; +public class PrecontratoBuilder : Builder { + public PrecontratoBuilder SetHabilitado(){ + data.Habilitado = 0; + return this; + } + + public PrecontratoBuilder SetInquilino(long dniInq) { + data.Dniinquilino = dniInq; + return this; + } + + public PrecontratoBuilder SetPropietario(long dniProp) { + data.Dnipropietario = dniProp; + return this; + } + + public PrecontratoBuilder SetPropiedad(int idprop) { + data.Idpropiedad = idprop; + return this; + } + + public PrecontratoBuilder SetCantidadGarantes(int cantgarante) { + data.Cantgarantemin = cantgarante; + return this; + } + + public PrecontratoBuilder SetIndiceActializacionInicial() { + data.Indiceactualizacion = 0.000M; + return this; + } + + public PrecontratoBuilder SetMesesHastaAumento(int meses) { + data.MesesHastaAumento = meses; + return this; + } + + public PrecontratoBuilder SetFecha(DateTime fechaprimernotificacion){ + data.Fechainicio = fechaprimernotificacion; + return this; + } +} \ No newline at end of file diff --git a/Aspnet/Controllers/ContratoController.cs b/Aspnet/Controllers/ContratoController.cs index 23e2cfa..ad701a4 100644 --- a/Aspnet/Controllers/ContratoController.cs +++ b/Aspnet/Controllers/ContratoController.cs @@ -1,15 +1,141 @@ +using AlquilaFacil.Builder; +using Entidades; +using Entidades.Dto; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Modelo; namespace AlquilaFacil.Controllers; [ApiController] public class ContratoController: ControllerBase { - [HttpGet("api/contratos")] + [HttpGet("api/contratos")] //WIP public IActionResult ObtenerContratosPorUsuario([FromHeader(Name="Auth")]string Auth) { return Ok(); } + [HttpPost("api/contratos/precontrato")] + public IActionResult IniciarPrecontrato([FromHeader(Name = "Auth")]string Auth, [FromBody] PrecontratoDto dto) { + if (String.IsNullOrEmpty(Auth)) return Unauthorized(); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario"); + if (validacion1 == false) return Unauthorized(); + + string validacion2 = ValidarDtoPrecontrato(dto); + if (validacion2 != "") return BadRequest(new {message = validacion2}); + + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new {message = "Tu token no corresponde a ningun cliente (volvete a logear)"}); + if (cli.Email != dto.EmailPropietario) return BadRequest(new {message = "No Corresponde el email de propietario con el del token"}); + + Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(dto.EmailPropietario); + if (propi == null || propi.Dni == 0) return BadRequest(new {message = "No hay propietario por ese email"}); + + Cliente? inq = RepositorioInquilinos.Singleton.ObtenerInquilinoPorEmail(dto.EmailInquilino); + if (inq == null || inq.Dni == 0) return BadRequest(new {message = "No hay inquilinos por ese email"}); + + Propiedade? p = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.IdPropiedad); + if (p == null || p.Id == 0) return BadRequest(new {message = "La id de propiedad no corresponde a una propiedad"}); + + var precontrato = new PrecontratoBuilder() + .SetHabilitado() + .SetPropietario(propi.Dni) + .SetInquilino(inq.Dni) + .SetCantidadGarantes(dto.CantidadGarantes) + .SetIndiceActializacionInicial() + .SetMesesHastaAumento(dto.MesesHastaAumento) + .SetPropiedad(p.Id) + .SetFecha(dto.fechaprimernotificacion) + .Build(); + + var notificacion = new NotificacioneBuilder() + .SetAccion("Carge Garantes") + .SetDniremitente(propi.Dni) + .SetDnicliente(inq.Dni) + .SetLeido(false) + .SetFecha(DateTime.Now) + .SetIdpropiedad(p.Id) + .SetMensaje($"El propietario {propi.Nombre} {propi.Apellido} te requiere que carges informacion de {dto.CantidadGarantes} Garantes") + .Build(); + + var ret = RepositorioContratos.Singleton.CargaPrecontrato(precontrato, notificacion); + + return (ret)? + Ok(new {message = "Se Cargo el precontrato y envio una notificacion al inquilino"}): + BadRequest(new {message = "No se pudo cargar el precontrato"}); + } - + [HttpPut("api/contratos/addGarantes")] + public IActionResult AddGarantes([FromHeader(Name = "Auth")]string Auth, AltaGarantesDto dto) { + if (String.IsNullOrWhiteSpace(Auth)) return BadRequest(""); + var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino"); + if (validacion1 == false) return Unauthorized(); + + var validacion2 = ValidarDtoAltaGarantes(dto); + if (validacion2 != "") return BadRequest(new {message = validacion2}); + + var validacion4 = RepositorioContratos.Singleton.CantidadGarantesEncontrato(dto.EmailInquilino, dto.Idpropiedad); + if (validacion4 <= 0 || dto.garantes.Count()!=validacion4) return BadRequest(new{message="Cantidad de garantes incorrecta"}); + + foreach (var i in dto.garantes) { + string validacion3 = ValidarDtoGarante(i); + if (validacion3 != "") return BadRequest( new { message = validacion3 }); + } + + List gar = new(); + + foreach (var i in dto.garantes) { + Garante g = new GaranteBuilder() + .SetNombre(i.Nombre) + .SetApellido(i.Apellido) + .SetCelular(i.Celular) + .SetDomicilio(i.Domicilio) + .SetDni(i.Dni) + .SetDomicilioLaboral(i.Domiciliolaboral) + .Build(); + gar.Add(g); + } + + var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad); + + return ret ? + Ok(new {message = "Se Añadieron los Garantes"}):BadRequest(new { message = "Fallo la carga"}); + } + + + private string ValidarDtoGarante(GaranteDto g){ + string ret = ""; + if (g == null) return "dto nulo"; + + if (g.Celular == "") ret += "No puede tener un numero de telefono vacio\n"; + if (g.Nombre == "") ret += "No puede tener un nombre vacio\n"; + if (g.Apellido == "") ret += "No puede tener un apellido vacio\n"; + if (g.Domiciliolaboral == "") ret += "Tiene que especificar su domicilio laboral\n"; + if (g.Domicilio == "") ret += "Tiene que especificar su domilio\n"; + + return ret; + } + + private string ValidarDtoAltaGarantes(AltaGarantesDto dto){ + string ret = ""; + if (dto == null) return "dto nulo"; + + if (dto.garantes.Count()<=0) ret += "No se puede tener 0 o menos garantes\n"; + if (dto.Idpropiedad<=0) ret += "la id de propiedad no puede ser igual o menor a 0\n"; + if (dto.EmailInquilino == "") ret += "El email de inquilino no puede estar vacio\n"; + + return ret; + } + private string ValidarDtoPrecontrato( PrecontratoDto dto) { + string ret = ""; + if (dto == null) return "dto nulo"; + + if (dto.CantidadGarantes<0) ret += "la cantidad de garantes necesarios no pueden ser menor a 0\n"; + if (dto.EmailInquilino == "") ret += "el email del inquilino no puede ser nulo\n"; + if (dto.EmailPropietario == "") ret += "el email del propietario no puede estar vacio\n"; + if (dto.IdPropiedad <= 0) ret += "la id de propiedad no puede ser igual o menor a 0\n"; + if (dto.MesesHastaAumento <= 0) ret += "No puede tener 0 o menos meses hasta el aumento\n"; + + return ret; + } + } \ No newline at end of file diff --git a/Aspnet/Controllers/NotificacionesController.cs b/Aspnet/Controllers/NotificacionesController.cs index e34d816..bef68eb 100644 --- a/Aspnet/Controllers/NotificacionesController.cs +++ b/Aspnet/Controllers/NotificacionesController.cs @@ -15,19 +15,20 @@ public class NotificacionesController: ControllerBase { var cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); if (cli == null) return BadRequest(new {message = "Fallo al intentar encontrar tu usuario (puede que te hayas logeado desde otro dispositivo?)"}); - LinkedList noti = new(); - var notificaciones = cli.NotificacioneDniclienteNavigations.Where(x=>x.Leido == leido).ToList(); - + + IQueryable notificaciones = RepositorioNotificaciones.Singleton.ObtenerNotificacionesDeUsuario(cli.Dni) + .Where(x=>x.Leido == leido); + List noti = new(); Parallel.ForEach(notificaciones, i => { var dto = new NotificacionDtoBuilder() - .SetRemitente(i.DniremitenteNavigation.Nombre) + .SetRemitente(i.DniremitenteNavigation.Email) .SetAccion(i.Accion) .SetMensaje(i.Mensaje) .SetFecha(i.Fecha) - .SetPropiedad(i.IdpropiedadNavigation.Ubicacion) - .Build(); + .SetPropiedad(i.IdpropiedadNavigation.Id.ToString()) + .Build(); - noti.AddFirst(dto); + noti.Add(dto); }); return Ok(noti); } @@ -53,7 +54,7 @@ public class NotificacionesController: ControllerBase { [HttpPost("api/notificaciones/consultaAlquiler")] public IActionResult ConsultaAlquiler([FromHeader(Name ="Auth")]string Auth, [FromBody] AltaNotificacionDto data) { if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized(); - bool validacion1 = RepositorioUsuarios.Singleton.CheckToken(Auth, data.Remitente); + bool validacion1 = RepositorioUsuarios.Singleton.CheckToken(data.Remitente, Auth); if (validacion1 == false) return BadRequest(new {message = "el token no corresponde a su usuario"}); if (data.Accion == "") return BadRequest(new{message = "El campo Accion esta vacio"}); diff --git a/Entidades/Dto/AltaGarantesDto.cs b/Entidades/Dto/AltaGarantesDto.cs new file mode 100644 index 0000000..c1971b9 --- /dev/null +++ b/Entidades/Dto/AltaGarantesDto.cs @@ -0,0 +1,9 @@ +namespace Entidades.Dto; + +public class AltaGarantesDto { + public string EmailInquilino { get; set; } = ""; + public int Idpropiedad {get; set;} + public DateTime fecha { get; set;} + public List garantes{ get; set; } = new(); + +} \ No newline at end of file diff --git a/Entidades/Dto/CrearContratoDto.cs b/Entidades/Dto/CrearContratoDto.cs deleted file mode 100644 index bfd023f..0000000 --- a/Entidades/Dto/CrearContratoDto.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Entidades.Dto; -//WIP -public class CrearContratoDto { - public int Meses {get; set;} - public int Idpropiedad {get; set;} - -} \ No newline at end of file diff --git a/Entidades/Dto/GaranteDto.cs b/Entidades/Dto/GaranteDto.cs new file mode 100644 index 0000000..736473e --- /dev/null +++ b/Entidades/Dto/GaranteDto.cs @@ -0,0 +1,16 @@ +namespace Entidades.Dto; + +public class GaranteDto { + public long Dni { get; set; } + + public string Nombre { get; set; } = null!; + + public string Apellido { get; set; } = null!; + + public string Domicilio { get; set; } = null!; + + public string Celular { get; set; } = null!; + + public string Domiciliolaboral { get; set; } = null!; + +} \ No newline at end of file diff --git a/Entidades/Dto/PrecontratoDto.cs b/Entidades/Dto/PrecontratoDto.cs new file mode 100644 index 0000000..2eed9aa --- /dev/null +++ b/Entidades/Dto/PrecontratoDto.cs @@ -0,0 +1,10 @@ +namespace Entidades.Dto; +public class PrecontratoDto { + public string EmailInquilino { get; set; } = ""; + public string EmailPropietario { get; set; } = ""; + public int IdPropiedad { get; set; } + public int CantidadGarantes { get; set; } + public int MesesHastaAumento { get; set; } + public bool TieneOpcionVenta { get; set; } + public DateTime fechaprimernotificacion { get; set; } +} \ No newline at end of file diff --git a/Front/src/Componentes/PublicacionPropiedad.svelte b/Front/src/Componentes/PublicacionPropiedad.svelte index c921590..8008fbb 100644 --- a/Front/src/Componentes/PublicacionPropiedad.svelte +++ b/Front/src/Componentes/PublicacionPropiedad.svelte @@ -2,15 +2,19 @@ import type { PropiedadDto } from "../types"; import ModalConfirm from "./ModalConfirm.svelte"; import {urlG} from "../stores/urlStore"; + import ModalEstatico from "./ModalEstatico.svelte"; let { prop }: { prop: PropiedadDto } = $props(); let show: boolean = $state(false); let token = sessionStorage.getItem("token"); let remitente = localStorage.getItem("email"); + const accion = "Nuevo Alquiler"; + let modaldata = $state(""); + let mensaje = `Alquiler: ${prop.ubicacion} a ${remitente}`; const message: string = "Queres consultar con el propietario por el alquiler? (esto le envia una notificacion y email al propietario)"; - const accion = "Consulta Nuevo Alquiler"; + function Consultar() { show = true; @@ -19,14 +23,18 @@ async function onConfirm() { const propiedad = prop.id; try { - const responce = await fetch($urlG+"/api/notificaciones", { + const responce = await fetch($urlG+"/api/notificaciones/consultaAlquiler", { method: "POST", headers: { - "Auth": String(token) + "Auth": String(token), + "Content-Type": "application/json" }, - body : JSON.stringify({remitente, accion, propiedad}) + body : JSON.stringify({remitente, accion, mensaje, propiedad}) }); + if (responce.ok){ + let data = await responce.json(); + } } catch { } @@ -40,6 +48,11 @@ +{#if modaldata} + !!(modaldata = "")} /> +{/if} + +
diff --git a/Front/src/paginas/Notificaciones.svelte b/Front/src/paginas/Notificaciones.svelte index 7b70d96..4122595 100644 --- a/Front/src/paginas/Notificaciones.svelte +++ b/Front/src/paginas/Notificaciones.svelte @@ -3,26 +3,113 @@ import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte"; import type { MensajeDto } from "../types"; import ModalEstatico from "../Componentes/ModalEstatico.svelte"; + import { urlG } from "../stores/urlStore"; + import ModalConfirm from "../Componentes/ModalConfirm.svelte"; + import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte"; + import { text } from "@sveltejs/kit"; const token = sessionStorage.getItem("token"); let mensajes: MensajeDto[] = $state([]); let showspinner:boolean =$state(false); let mostrarleidos: boolean = $state(false); let modaldata:string =$state(""); + let Selmens: MensajeDto; + + let show:boolean = $state(false); + let title:string = $state(""); + let message:string = $state(""); onMount(async () => { - showspinner = true; SinLeer(); }) async function SinLeer() { mostrarleidos = false; + showspinner = true; + try{ + const responce = await fetch($urlG+"/api/notificaciones?leido="+mostrarleidos, { + method: "GET", + headers: { + "Auth": String(token) + } + }); + if (responce.ok) { + let data = await responce.json(); + mensajes = data; + showspinner = false; + return; + } + let errordata = await responce.json(); + modaldata = errordata.message; + } catch{ + modaldata = "no se pudo obtener notificaciones"; + } } async function Leidos() { mostrarleidos = true; + showspinner = true; + try { + const responce = await fetch($urlG+"/api/notificaciones?leido="+true, { + method: "GET", + headers: { + "Auth": String(token) + } + }); + if (responce.ok) { + let data = await responce.json(); + mensajes = data; + showspinner = false; + return; + } + let errordata = await responce.json(); + modaldata = errordata.message; + } catch { + modaldata = "no se pudo obtener notificaciones"; + } } + + function setModalConfirm(men:MensajeDto){ + Selmens = men; + message = "${}" + show = true; + + } + + async function marcarleido( fecha: Date, email: string, men:MensajeDto ) { + show = true; + + try { + const responce = await fetch($urlG+"/api/notificaciones", { + method: "PUT", + headers: { + "Auth": String(token), + "Content-Type": "application/json", + }, + body: JSON.stringify({fecha, email}), + }); + if (responce.ok) { + let data = await responce.json(); + modaldata = data.message; + mensajes = mensajes.filter(m => m !== men); + return; + } + let dataerror = await responce.json(); + modaldata = dataerror.message; + } catch { + modaldata = "no se pudo marcar como leido"; + } + } + + + function abrirModal(mensaje: MensajeDto) { + Selmens = mensaje; + title = "Confirmar proceso de alquiler"; + message ="Aceptar este proceso eliminará la propiedad del menú de búsqueda. Se informará al inquilino que debe pasar los datos de sus garantías. ¿Desea continuar?"; + show = true; + } + @@ -31,8 +118,17 @@ !!(modaldata = "")} /> {/if} + (show = false)} + onConfirm={()=>1+1} +/>

+ +
@@ -47,7 +143,7 @@
{:else} - +
@@ -55,19 +151,41 @@ + {#if mostrarleidos == false} + + {/if} - {#each mensajes as men } + {#if mensajes.length <= 0} - - - - - + + + {:else} + {#each mensajes as men} + + + + + + + + {#if mostrarleidos == false} + + {/if} {/each} + {/if}
RemitenteMensaje Fecha Propiedad
men.remitentemen.accionmen.mensajemen.fechamen.propiedad +

No hay Mensajes para leer

+
{men.remitente}{men.accion}{men.mensaje}{men.fecha}{men.propiedad} + +
{/if} diff --git a/Modelo/RepositorioContratos.cs b/Modelo/RepositorioContratos.cs index 1d9ebfa..9cefd94 100644 --- a/Modelo/RepositorioContratos.cs +++ b/Modelo/RepositorioContratos.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; namespace Modelo; public class RepositorioContratos: RepositorioBase { - public IQueryable? ObtenerContratosPorEmailInquilino(string email){ + public IQueryable? ObtenerContratosPorEmailInquilino(string email) { var con = Context; try{ var listcont = con.Contratos.Where(x=>x.DniinquilinoNavigation.Email == email); @@ -12,4 +12,47 @@ public class RepositorioContratos: RepositorioBase { return null; } } + + public bool CargaPrecontrato(Contrato? c = null, Notificacione? n = null) { + if (c == null || c.Habilitado == 1) return false; + if (n == null) return false; + var con = Context; + + var prop = con.Propiedades.FirstOrDefault(x=>x.Id==c.Idpropiedad); + if (prop == null) return false; + prop.Idestado = 2; + + c.Id = con.Contratos.Max(x=>x.Id)+1; + c.Monto = prop.Monto; + + con.Contratos.Add(c); + con.Notificaciones.Add(n); + + return Guardar(con); + } + public bool CargaGarantes(List gar, string emailInquilino, int idpropiedad) { + var con = Context; + Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation) + .FirstOrDefault(x=>x.Idpropiedad == idpropiedad && + x.DniinquilinoNavigation.Email == emailInquilino && + x.Habilitado == 0); + + if (contr == null) return false; + foreach (var i in gar) { + i.Id = con.Garantes.Max(x=>x.Id)+1; + contr.Idgarantes.Add(i); + } + + return Guardar(con); + } + + public int CantidadGarantesEncontrato(string emailInquilino, int idpropiedad) { + var con = Context; + Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation) + .FirstOrDefault(x=>x.Idpropiedad == idpropiedad && + x.DniinquilinoNavigation.Email == emailInquilino && + x.Habilitado == 0); + if (contr == null) return 0; + return contr.Cantgarantemin; + } } diff --git a/Modelo/RepositorioGrupos.cs b/Modelo/RepositorioGrupos.cs index 28e1fa3..81cc13d 100644 --- a/Modelo/RepositorioGrupos.cs +++ b/Modelo/RepositorioGrupos.cs @@ -32,4 +32,18 @@ public class RepositorioGrupos: RepositorioBase { }); return grupos; } + + public bool CheckGrupos(string token, string grupo){ + var con = Context; + Cliente? cli = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Token == token); + if (cli == null) return false; + + Grupo? gru = con.Grupos.FirstOrDefault(x=>x.Nombre == grupo); + if (gru == null) return false; + + if (cli.Idgrupos.Contains(gru)) return true; + + return false; + + } } \ No newline at end of file diff --git a/Modelo/RepositorioInquilinos.cs b/Modelo/RepositorioInquilinos.cs index 48de959..1f55265 100644 --- a/Modelo/RepositorioInquilinos.cs +++ b/Modelo/RepositorioInquilinos.cs @@ -1,3 +1,4 @@ +using Entidades; using Entidades.Dto; using Microsoft.EntityFrameworkCore; @@ -15,5 +16,15 @@ public class RepositorioInquilinos: RepositorioBase { return Context.Database.SqlQuery(sqlq); } + public Cliente? ObtenerInquilinoPorEmail(string Email){ + var con = Context; + Cliente? cli = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Email == Email); + if (cli == null || cli.Dni == 0) return null; + + Grupo? gru = cli.Idgrupos.FirstOrDefault(x=>x.Id == 2); + if (gru == null) return null; + + return cli; + } } \ No newline at end of file diff --git a/Modelo/RepositorioNotificaciones.cs b/Modelo/RepositorioNotificaciones.cs index 6a3dae1..1a8aaae 100644 --- a/Modelo/RepositorioNotificaciones.cs +++ b/Modelo/RepositorioNotificaciones.cs @@ -3,6 +3,7 @@ using System.Text; using Entidades.Dto; using Entidades; using Microsoft.EntityFrameworkCore; +using System.Collections.Concurrent; namespace Modelo; @@ -20,7 +21,18 @@ public class RepositorioNotificaciones : RepositorioBase ObtenerNotificacionesDeUsuario(long dni) { + var con = Context; + + var notis = con.Notificaciones + .Include(x=>x.IdpropiedadNavigation) + .Include(x=>x.DniremitenteNavigation) + .Where(x => x.Dnicliente == dni); + return notis; + } } \ No newline at end of file diff --git a/Modelo/RepositorioPermisos.cs b/Modelo/RepositorioPermisos.cs index e53fb40..e92a993 100644 --- a/Modelo/RepositorioPermisos.cs +++ b/Modelo/RepositorioPermisos.cs @@ -34,6 +34,7 @@ public class RepositorioPermisos: RepositorioBase { ///////////////////////////////////////////////////////////////// //Esto esta comentado porque antes pasaba el string del path de la url, es una mala idea a muchos niveles + // abajo un comentario viejo mio ///////////////////////////////////////////////////////////////// //me inspiré y hice un regex pero si eliminaba los primeros 8(?) caracteres del string era lo mismo //Match match = Regex.Match(path, @"^/accion/(\d+)$"); diff --git a/Modelo/RepositorioPropiedades.cs b/Modelo/RepositorioPropiedades.cs index a5ca3d6..161e317 100644 --- a/Modelo/RepositorioPropiedades.cs +++ b/Modelo/RepositorioPropiedades.cs @@ -27,14 +27,9 @@ public class RepositorioPropiedades: RepositorioBase { } public Propiedade? ObtenerPropiedadPorId(int Id) { + var con = Context; + Propiedade? prop = con.Propiedades.Include(x=>x.DnipropietarioNavigation).FirstOrDefault(x=>x.Id == Id); - FormattableString sqlq = $""" - SELECT * FROM Propiedades p - WHERE p.id = {Id} - LIMIT 1 - """; - - Propiedade? prop = Context.Database.SqlQuery(sqlq).First(); if (prop == null || prop.Id == 0) { return null; } diff --git a/Modelo/RepositorioPropietario.cs b/Modelo/RepositorioPropietario.cs index e8636dd..ef2ef97 100644 --- a/Modelo/RepositorioPropietario.cs +++ b/Modelo/RepositorioPropietario.cs @@ -25,9 +25,10 @@ public class RepositorioPropietario: RepositorioBase { public Cliente? ObtenerPropietarioPorEmail(string email){ var con = Context; - Cliente? cli = con.Clientes.FirstOrDefault(x=>x.Email == email); + Cliente? cli = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Email == email); if (cli == null|| cli.Dni == 0) return null; - if (cli.Dni == 0 || cli == null) return null; + var grupo = cli.Idgrupos.FirstOrDefault(x=>x.Id == 1); + if (grupo == null) return null; return cli; } } diff --git a/Modelo/RepositorioUsuarios.cs b/Modelo/RepositorioUsuarios.cs index 29afb78..f0dd6af 100644 --- a/Modelo/RepositorioUsuarios.cs +++ b/Modelo/RepositorioUsuarios.cs @@ -88,10 +88,6 @@ public class RepositorioUsuarios: RepositorioBase { var usu = Context.Clientes.FirstOrDefault(x => x.Email == email); if (usu == null) return false; - #if DEBUG - //Console.WriteLine(token + "\n" +usu.Token); - #endif - return usu.Token == token; }