un corte que hago a las 19hs
This commit is contained in:
@@ -4,6 +4,7 @@ using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Modelo;
|
||||
using ZstdSharp.Unsafe;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
@@ -141,7 +142,76 @@ public class ContratoController: ControllerBase {
|
||||
if (pro == null) return BadRequest(new {message = "No Existe Usuario con ese email"});
|
||||
if (pro.Token != Auth) return BadRequest(new {message = "El token de auth no corresponde al token el usuario propietario"});
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad);
|
||||
if (prop == null) return BadRequest(new {message = "No existe la propiedad por esa id"});
|
||||
if (prop.Dnipropietario != pro.Dni) return BadRequest(new {message = "Este propietario no es el dueño de la propiedad"});
|
||||
|
||||
var inq = RepositorioInquilinos.Singleton.ObtenerInquilinoPorEmail(dto.EmailInquilino);
|
||||
if (inq == null) return BadRequest(new {message = "No hay un inquilino por ese email"});
|
||||
|
||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad);
|
||||
if (ret) {
|
||||
prop.Idestado = 1;
|
||||
ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop);
|
||||
if (ret){
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(pro.Dni, dto.fecha);
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("ContratoCancelado")
|
||||
.SetIdpropiedad(dto.idpropiedad)
|
||||
.SetDniremitente(pro.Dni)
|
||||
.SetDnicliente(inq.Dni)
|
||||
.SetMensaje($"Se cancelo el intento de alquilar la propiedad: {dto.idpropiedad}")
|
||||
.SetIdpropiedad(dto.idpropiedad)
|
||||
.SetLeido(false)
|
||||
.Build();
|
||||
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
if (ret){
|
||||
return Ok(new {message = "Se cancelo el precontrato"});
|
||||
}else{
|
||||
return Ok(new {message = "Se cancelo el precontrato, pero no se pudo notificar al inquilino"});
|
||||
}
|
||||
}else{
|
||||
return BadRequest(new {message = "No se pudo setear la propiedad como Disponible en busqueda"});
|
||||
}
|
||||
}else{
|
||||
return BadRequest(new {message = "Se fallo al intentar cancelar el precontrato"});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("api/contratos/precontrato/listaGarantes")]
|
||||
public IActionResult ObtenerListaGarantes([FromHeader(Name = "Auth")]string Auth, long idcontrato = 0, [FromQuery] string EmailPropietario = "" ) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (idcontrato == 0 || EmailPropietario == "") return BadRequest(new { message = "Estan mal cargados los datos"});
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return BadRequest(new {message = "No hay un propietario por ese token"});
|
||||
if (cli.Email != EmailPropietario) return BadRequest(new {message = "El Email del usuario no coinside con el del token"});
|
||||
|
||||
Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato);
|
||||
if (contr == null) return BadRequest(new {message = "No hay un precontrato por esa id"});
|
||||
|
||||
return Ok(contr.Idgarantes);
|
||||
}
|
||||
|
||||
[HttpPost("api/contratos/subirContrato")]
|
||||
public IActionResult subirContrato([FromHeader(Name = "Auth")]string Auth, [FromForm] IFormFile contrato) {
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
return Ok();
|
||||
|
||||
}
|
||||
|
||||
[HttpPost("api/contratos/aceptarContrato")]
|
||||
public IActionResult AceptarContrato([FromHeader(Name = "Auth")]string Auth){
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private string ValidarCancelarDto(CancelarPrecontratoDto dto) {
|
||||
@@ -152,7 +222,9 @@ public class ContratoController: ControllerBase {
|
||||
if (dto.EmailPropietario =="") ret += "No puede tener un EmailPropietario Vacio\n";
|
||||
if (dto.idpropiedad <= 0 ) ret += "No puede tener id propiedad igual o menor a 0\n";
|
||||
if (dto.fecha == DateTime.MinValue) ret += "Falta fecha\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
private string ValidarDtoGarante(GaranteDto g) {
|
||||
string ret = "";
|
||||
if (g == null) return "dto nulo";
|
||||
|
||||
@@ -1,21 +1,63 @@
|
||||
<script lang="ts">
|
||||
import type { MensajeDto } from "../types";
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import type { GaranteDto, MensajeDto } from "../types";
|
||||
|
||||
let {men, onCancel, onConfirm, putErrorModal}: {men: MensajeDto,
|
||||
onCancel:()=>void,
|
||||
onConfirm:()=>void,
|
||||
putErrorModal:(txt:string)=>void} = $props();
|
||||
let {men, garantes , onCancel, onConfirm, onClose
|
||||
} : {
|
||||
men: MensajeDto,
|
||||
garantes: GaranteDto[],
|
||||
onCancel:()=>void,
|
||||
onClose:()=>void,
|
||||
onConfirm:()=>void } = $props();
|
||||
|
||||
let confirmaGarantes: boolean = $state(false);
|
||||
|
||||
async function getGaranteData() {
|
||||
try {
|
||||
const responce = await fetch($urlG+"". {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Auth": String(sessionStorage.getItem("token")),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div class="modal show d-block" tabindex="-1" role="dialog" aria-labelledby="staticModalLabel" aria-hidden="true" style="background-color: rgba(0,0,0,0.5);">
|
||||
<div class="modal-dialog modal-xl" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="staticModalLabel">Lista de Garantes y subir Contrato</h5>
|
||||
<button type="button" class="btn-close" aria-label="Close" onclick={onClose}></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>DNI</th>
|
||||
<th>Nombre</th>
|
||||
<th>Apellido</th>
|
||||
<th>Domicilio</th>
|
||||
<th>Celular</th>
|
||||
<th>Domicilio Laboral</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each garantes as garante, index}
|
||||
<tr>
|
||||
<td>{index + 1}</td>
|
||||
<td>{garante.Dni}</td>
|
||||
<td>{garante.Nombre}</td>
|
||||
<td>{garante.Apellido}</td>
|
||||
<td>{garante.Domicilio}</td>
|
||||
<td>{garante.Celular}</td>
|
||||
<td>{garante.Domiciliolaboral}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="checkbox" bind:checked={confirmaGarantes} disabled={confirmaGarantes}>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between">
|
||||
<button class="btn btn-primary" disabled={!confirmaGarantes} onclick={() => onConfirm()} >
|
||||
Subir
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" onclick={onCancel}>Cancelar Contrato</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,17 +10,21 @@
|
||||
import ModalPrecontrato from "../Componentes/ModalPrecontrato.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import ModalAddGarantes from "../Componentes/ModalAddGarantes.svelte";
|
||||
import { Accordion } from "@sveltestrap/sveltestrap";
|
||||
import ModalCheckYContrato from "../Componentes/ModalCheckYContrato.svelte";
|
||||
|
||||
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 = $state({accion: "",receptor:"", fecha: Date.UTC, mensaje:"", propiedad:0, remitente:""});
|
||||
let Selmens: MensajeDto = $state({accion:""});
|
||||
|
||||
let show:boolean = $state(false);
|
||||
let setCantGarantes = $state(0);
|
||||
|
||||
let garantes:GaranteDto[] = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
SinLeer();
|
||||
})
|
||||
@@ -72,8 +76,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function marcarleido( fecha: Date, email: string, men:MensajeDto ) {
|
||||
show = true;
|
||||
|
||||
@@ -104,7 +106,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
function abrirModal(mensaje: MensajeDto) {
|
||||
if (mensaje.accion === "Nuevo Alquiler") {
|
||||
Selmens = { ...mensaje };
|
||||
return;
|
||||
@@ -115,6 +117,12 @@
|
||||
setCantGarantes = Number(Selmens.mensaje.split(" ").reverse()[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mensaje.accion === "Check y Contrato"){
|
||||
Selmens = {...mensaje};
|
||||
let idcontrato = Number(Selmens.mensaje.split(" ").reverse()[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje2(data: {opcionVenta:boolean, cantGarantes:number, mesesHastaAumento:number}) {
|
||||
@@ -197,6 +205,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleCancelPrecontrato(): void {
|
||||
|
||||
}
|
||||
|
||||
async function handleEnviarmensaje4() {
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
@@ -205,20 +221,14 @@
|
||||
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")} />
|
||||
{/if}
|
||||
|
||||
<!--
|
||||
<ModalConfirm
|
||||
{show}
|
||||
{title}
|
||||
{message}
|
||||
onCancel={() => (show = false)}
|
||||
onConfirm={()=>1+1}
|
||||
/>
|
||||
-->
|
||||
{#if Selmens.accion == "Nuevo Alquiler" }
|
||||
<ModalPrecontrato onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje2} />
|
||||
{:else if Selmens.accion == "Carge Garantes"}
|
||||
<ModalAddGarantes maxGarantes={setCantGarantes} onClose={() => (Selmens.accion = "")} onSubmit={handleEnviarmensaje3}/>
|
||||
{:else if Selmens.accion == "Check y Contrato"}
|
||||
<ModalCheckYContrato {garantes} men={Selmens} onCancel={handleCancelPrecontrato} onClose={() => (Selmens.accion = "")} onConfirm={handleEnviarmensaje4}/>
|
||||
{/if}
|
||||
|
||||
<div class="container">
|
||||
<br>
|
||||
<BarraHorizontalConTexto text="Notificaciones"/>
|
||||
@@ -271,24 +281,23 @@
|
||||
|
||||
{#if mostrarleidos == false}
|
||||
<td>
|
||||
<div class="d-flex">
|
||||
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
onclick={() => marcarleido(men.fecha, localStorage.getItem("email")|| "", men)}
|
||||
>
|
||||
Marcar Leido
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
class="btn btn-outline-primary"
|
||||
onclick={() => abrirModal(men)}
|
||||
>
|
||||
Expandir
|
||||
</button>
|
||||
</td>
|
||||
{/if}
|
||||
{:else if men.accion == "ContratoCancelado"}
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-outline-danger"
|
||||
onclick={() => marcarleido(men.fecha, localStorage.getItem("email")|| "", men)}
|
||||
>
|
||||
Marcar Leido
|
||||
</button>
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -72,4 +72,25 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||
return contr;
|
||||
|
||||
}
|
||||
|
||||
public bool CancelarPrecontrato(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 &&
|
||||
x.Cancelado == 0);
|
||||
|
||||
if (contr == null) return false;
|
||||
contr.Cancelado = 1;
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public Contrato? ObtenerPreContratoPorId(long idcontrato) {
|
||||
var con = Context;
|
||||
Contrato? contr = con.Contratos.Include(x=>x.Idgarantes).Where(x=>x.Cancelado == 0 && x.Habilitado == 0)
|
||||
.FirstOrDefault(x=>x.Id == idcontrato);
|
||||
if (contr == null) return null;
|
||||
return contr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user