diff --git a/Aspnet/Builder/NotificacionDtoBuilder.cs b/Aspnet/Builder/NotificacionDtoBuilder.cs index 8141110..7f9cfdb 100644 --- a/Aspnet/Builder/NotificacionDtoBuilder.cs +++ b/Aspnet/Builder/NotificacionDtoBuilder.cs @@ -27,4 +27,8 @@ public class NotificacionDtoBuilder: Builder { return this; } + public NotificacionDtoBuilder SetReceptor(string receptor) { + data.Receptor = receptor; + return this; + } } \ No newline at end of file diff --git a/Aspnet/Controllers/ContratoController.cs b/Aspnet/Controllers/ContratoController.cs index ad701a4..132cf39 100644 --- a/Aspnet/Controllers/ContratoController.cs +++ b/Aspnet/Controllers/ContratoController.cs @@ -44,9 +44,10 @@ public class ContratoController: ControllerBase { .SetIndiceActializacionInicial() .SetMesesHastaAumento(dto.MesesHastaAumento) .SetPropiedad(p.Id) - .SetFecha(dto.fechaprimernotificacion) + .SetFecha(DateTime.Parse(dto.fechaprimernotificacion)) .Build(); + var notificacion = new NotificacioneBuilder() .SetAccion("Carge Garantes") .SetDniremitente(propi.Dni) @@ -58,7 +59,9 @@ public class ContratoController: ControllerBase { .Build(); var ret = RepositorioContratos.Singleton.CargaPrecontrato(precontrato, notificacion); - + if (ret) { + ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion)); + } return (ret)? Ok(new {message = "Se Cargo el precontrato y envio una notificacion al inquilino"}): BadRequest(new {message = "No se pudo cargar el precontrato"}); @@ -73,9 +76,16 @@ public class ContratoController: ControllerBase { var validacion2 = ValidarDtoAltaGarantes(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.EmailInquilino) return BadRequest(new {message = "No Corresponde el email de inquilino con el del token"}); + var validacion4 = RepositorioContratos.Singleton.CantidadGarantesEncontrato(dto.EmailInquilino, dto.Idpropiedad); if (validacion4 <= 0 || dto.garantes.Count()!=validacion4) return BadRequest(new{message="Cantidad de garantes incorrecta"}); + Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorIdPropiedad(dto.Idpropiedad); + if(propi == null) return BadRequest(new{message = "No se encuentra el propietario de la propiedad"}); + foreach (var i in dto.garantes) { string validacion3 = ValidarDtoGarante(i); if (validacion3 != "") return BadRequest( new { message = validacion3 }); @@ -96,6 +106,22 @@ public class ContratoController: ControllerBase { } var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad); + if (ret) { + Console.WriteLine(dto.fecha); + ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.fecha); + + var noti = new NotificacioneBuilder() + .SetIdpropiedad(dto.Idpropiedad) + .SetAccion("Comprobar Garantes") + .SetMensaje($"") + .SetLeido(false) + .SetDniremitente(cli.Dni) + .SetDnicliente() + .SetFecha(DateTime.Now) + + .Build() + } + return ret ? Ok(new {message = "Se Añadieron los Garantes"}):BadRequest(new { message = "Fallo la carga"}); diff --git a/Aspnet/Controllers/NotificacionesController.cs b/Aspnet/Controllers/NotificacionesController.cs index bef68eb..1eb040e 100644 --- a/Aspnet/Controllers/NotificacionesController.cs +++ b/Aspnet/Controllers/NotificacionesController.cs @@ -26,6 +26,7 @@ public class NotificacionesController: ControllerBase { .SetMensaje(i.Mensaje) .SetFecha(i.Fecha) .SetPropiedad(i.IdpropiedadNavigation.Id.ToString()) + .SetReceptor(i.DniclienteNavigation.Email) .Build(); noti.Add(dto); diff --git a/Entidades/Dto/NotificacionDto.cs b/Entidades/Dto/NotificacionDto.cs index 9a7e488..9daa73e 100644 --- a/Entidades/Dto/NotificacionDto.cs +++ b/Entidades/Dto/NotificacionDto.cs @@ -2,6 +2,7 @@ namespace Entidades.Dto; public class NotificacionDto { public string Remitente { get; set; } =""; public string Accion { get; set; } =""; + public string Receptor { get; set; } =""; public string Mensaje { get; set; } =""; public DateTime? Fecha{get; set;} =null; public string Propiedad { get; set;} =""; diff --git a/Entidades/Dto/PrecontratoDto.cs b/Entidades/Dto/PrecontratoDto.cs index 2eed9aa..206889e 100644 --- a/Entidades/Dto/PrecontratoDto.cs +++ b/Entidades/Dto/PrecontratoDto.cs @@ -6,5 +6,5 @@ public class PrecontratoDto { public int CantidadGarantes { get; set; } public int MesesHastaAumento { get; set; } public bool TieneOpcionVenta { get; set; } - public DateTime fechaprimernotificacion { get; set; } + public string fechaprimernotificacion { get; set; } } \ No newline at end of file diff --git a/Front/src/Componentes/ModalAddGarantes.svelte b/Front/src/Componentes/ModalAddGarantes.svelte new file mode 100644 index 0000000..ca0e721 --- /dev/null +++ b/Front/src/Componentes/ModalAddGarantes.svelte @@ -0,0 +1,165 @@ + + + diff --git a/Front/src/Componentes/ModalPrecontrato.svelte b/Front/src/Componentes/ModalPrecontrato.svelte new file mode 100644 index 0000000..d3d5dd4 --- /dev/null +++ b/Front/src/Componentes/ModalPrecontrato.svelte @@ -0,0 +1,50 @@ + + + \ No newline at end of file diff --git a/Front/src/paginas/Notificaciones.svelte b/Front/src/paginas/Notificaciones.svelte index 4122595..85196bf 100644 --- a/Front/src/paginas/Notificaciones.svelte +++ b/Front/src/paginas/Notificaciones.svelte @@ -1,23 +1,25 @@ @@ -118,13 +197,20 @@ !!(modaldata = "")} /> {/if} - (show = false)} onConfirm={()=>1+1} -/> + /> +--> +{#if Selmens.accion == "Nuevo Alquiler" } + (Selmens.accion = "")} onSubmit={handleEnviarmensaje2} /> +{:else if Selmens.accion == "Carge Garantes"} + (Selmens.accion = "")} onSubmit={handleEnviarmensaje3}/> +{/if}

@@ -148,6 +234,7 @@ Remitente Accion + Receptor Mensaje Fecha Propiedad @@ -169,18 +256,29 @@ {men.remitente} {men.accion} + {men.receptor} {men.mensaje} {men.fecha} {men.propiedad} {#if mostrarleidos == false} - +
+ + + + +
{/if} diff --git a/Front/src/types.d.ts b/Front/src/types.d.ts index 1733c51..cb2723e 100644 --- a/Front/src/types.d.ts +++ b/Front/src/types.d.ts @@ -58,8 +58,18 @@ export type Propiedad = { export type MensajeDto = { remitente: string, accion: string, + receptor: string, mensaje: string, fecha: Date, propiedad: string, -} \ No newline at end of file +} + +export type GaranteDto = { + Dni: number; + Nombre: string; + Apellido: string; + Domicilio: string; + Celular: string; + Domiciliolaboral: string; +}; diff --git a/Modelo/RepositorioContratos.cs b/Modelo/RepositorioContratos.cs index 9cefd94..351bdc0 100644 --- a/Modelo/RepositorioContratos.cs +++ b/Modelo/RepositorioContratos.cs @@ -22,7 +22,7 @@ public class RepositorioContratos: RepositorioBase { if (prop == null) return false; prop.Idestado = 2; - c.Id = con.Contratos.Max(x=>x.Id)+1; + c.Id = (con.Contratos.Any() ? con.Contratos.Max(x => x.Id) : 0) + 1; c.Monto = prop.Monto; con.Contratos.Add(c); @@ -32,14 +32,17 @@ public class RepositorioContratos: RepositorioBase { } public bool CargaGarantes(List gar, string emailInquilino, int idpropiedad) { var con = Context; - Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation) + Contrato? contr = con.Contratos.Include(x=>x.DniinquilinoNavigation).Include(x=>x.Idgarantes) .FirstOrDefault(x=>x.Idpropiedad == idpropiedad && x.DniinquilinoNavigation.Email == emailInquilino && x.Habilitado == 0); if (contr == null) return false; + int inicial = (con.Garantes.Any()? con.Garantes.Max(x=>x.Id): 0) + 1; foreach (var i in gar) { - i.Id = con.Garantes.Max(x=>x.Id)+1; + i.Id = inicial; + inicial++; + con.Garantes.Add(i); contr.Idgarantes.Add(i); } diff --git a/Modelo/RepositorioPropietario.cs b/Modelo/RepositorioPropietario.cs index ef2ef97..ee8fa75 100644 --- a/Modelo/RepositorioPropietario.cs +++ b/Modelo/RepositorioPropietario.cs @@ -31,4 +31,12 @@ public class RepositorioPropietario: RepositorioBase { if (grupo == null) return null; return cli; } + + public Cliente? ObtenerPropietarioPorIdPropiedad(int idpropiedad) { + var con = Context; + Propiedade? pro = con.Propiedades.Include(x=>x.DnipropietarioNavigation).FirstOrDefault(x=>x.Id == idpropiedad) + if (pro == null) return null; + + + } }