falta testear
This commit is contained in:
@@ -275,7 +275,7 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contrato/getdocumento")]
|
[HttpGet("api/contrato/getdocumento")]
|
||||||
public async Task<IActionResult> ObtenerContrato([FromHeader(Name = "Auth")]string Auth, [FromQuery]long idcontrato) {
|
public IActionResult ObtenerContrato([FromHeader(Name = "Auth")]string Auth, [FromQuery]long idcontrato) {
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -291,23 +291,23 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
string nuevoNombreArchivo = $"id:{contr.Id}-inq:{contr.Dniinquilino}-propi:{contr.Dnipropietario}-idprop:{contr.Idpropiedad}.pdf";
|
string nuevoNombreArchivo = $"id:{contr.Id}-inq:{contr.Dniinquilino}-propi:{contr.Dnipropietario}-idprop:{contr.Idpropiedad}.pdf";
|
||||||
try{
|
try{
|
||||||
using( var memstream = new MemoryStream()){
|
var memstream = new MemoryStream();
|
||||||
|
|
||||||
var goa = new GetObjectArgs()
|
var goa = new GetObjectArgs()
|
||||||
.WithBucket("alquilafacil")
|
.WithBucket("alquilafacil")
|
||||||
.WithObject(nuevoNombreArchivo)
|
.WithObject(nuevoNombreArchivo)
|
||||||
.WithCallbackStream(async stream => {
|
.WithCallbackStream(stream => {
|
||||||
memstream.Position=0;
|
memstream.Position=0;
|
||||||
await stream.CopyToAsync(memstream);
|
stream.CopyTo(memstream);
|
||||||
});
|
});
|
||||||
|
|
||||||
await mc.GetObjectAsync(goa);
|
mc.GetObjectAsync(goa).Wait();
|
||||||
memstream.Position = 0;
|
memstream.Position = 0;
|
||||||
|
|
||||||
if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" });
|
if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" });
|
||||||
|
|
||||||
return File(memstream.ToArray(), "application/pdf", nuevoNombreArchivo);
|
return File(memstream, "application/pdf", nuevoNombreArchivo);
|
||||||
}
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
Console.Error.WriteLine(e);
|
Console.Error.WriteLine(e);
|
||||||
return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"});
|
return BadRequest(new { message = "Fallo al intentar obtener el archivo del almacenamiento o este no existe"});
|
||||||
@@ -316,12 +316,75 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/aceptarContrato")]
|
[HttpPost("api/contratos/aceptarContrato")]
|
||||||
public IActionResult AceptarContrato([FromHeader(Name = "Auth")]string Auth){
|
public IActionResult AceptarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] AceptarContratoDto dto){
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest();
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
return Ok();
|
if (dto.Idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"});
|
||||||
|
|
||||||
|
Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(dto.Idcontrato);
|
||||||
|
if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un precontrato por esa id"});
|
||||||
|
|
||||||
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||||
|
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"});
|
||||||
|
|
||||||
|
bool ret = RepositorioContratos.Singleton.AceptarContrato(dto.Idcontrato);
|
||||||
|
if (ret == false) return BadRequest(new { message ="fallo al aceptar el contrato"});
|
||||||
|
|
||||||
|
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||||
|
|
||||||
|
var noti = new NotificacioneBuilder()
|
||||||
|
.SetDniremitente(cli.Dni)
|
||||||
|
.SetIdpropiedad(contr.Idpropiedad??0)
|
||||||
|
.SetDnicliente(contr.Dnipropietario??0)
|
||||||
|
.SetAccion("Aceptado Contrato")
|
||||||
|
.SetMensaje($"Se inicio el alquiler")
|
||||||
|
.SetFecha(DateTime.Now)
|
||||||
|
.SetLeido(false)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||||
|
return ret ?
|
||||||
|
Ok(new { message = "Se acepto el contrato y se crearon los Canons a ser pagados"}) :
|
||||||
|
BadRequest(new { message = "No se pudo aceptar el contrato"});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("api/contratos/rechazarPreContrato")]
|
||||||
|
public IActionResult CancelarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] RechazarPreContrato dto ) {
|
||||||
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest();
|
||||||
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
|
if (dto.Idcontrato <= 0) return BadRequest(new {message = "La id no puede ser igual o menor a 0"});
|
||||||
|
|
||||||
|
Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(dto.Idcontrato);
|
||||||
|
if (contr == null || contr.Dniinquilino == 0) return BadRequest(new { message = "No hay un precontrato por esa id"});
|
||||||
|
|
||||||
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token"});
|
||||||
|
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino"});
|
||||||
|
|
||||||
|
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.Idcontrato);
|
||||||
|
if (ret == false) return BadRequest(new {message = "Fallo al intentar cancelar el precontrato"});
|
||||||
|
|
||||||
|
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||||
|
var noti = new NotificacioneBuilder()
|
||||||
|
.SetDniremitente(cli.Dni)
|
||||||
|
.SetIdpropiedad(contr.Idpropiedad??0)
|
||||||
|
.SetDnicliente(contr.Dnipropietario??0)
|
||||||
|
.SetAccion("Rechazo Contrato")
|
||||||
|
.SetMensaje($"Se cancelo el proceso para alquilar de: {cli.Nombre}")
|
||||||
|
.SetFecha(DateTime.Now)
|
||||||
|
.SetLeido(false)
|
||||||
|
.Build();
|
||||||
|
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||||
|
|
||||||
|
return ret?
|
||||||
|
Ok(new { message = "Se cancelo el proceso para iniciar el alquiler"}):
|
||||||
|
BadRequest(new { message = "No se pudo cancelar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> subirContrato(IFormFile f, string flname) {
|
private async Task<bool> subirContrato(IFormFile f, string flname) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Minio;
|
using Minio;
|
||||||
using AlquilaFacil.Config;
|
using AlquilaFacil.Config;
|
||||||
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -19,6 +20,11 @@ builder.Services.AddMinio(options => options
|
|||||||
.WithSSL(false)
|
.WithSSL(false)
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
|
builder.Services.Configure<FormOptions>(options =>
|
||||||
|
{
|
||||||
|
options.MultipartBodyLengthLimit = 50 * 1024 * 1024; // 50 MB
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("AllowSvelteApp",
|
options.AddPolicy("AllowSvelteApp",
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"usr":"aVO9C3PqeK1hiPCyqZCj",
|
||||||
|
"scrt":"szj58kceWG3GcRZ8P1QCQiv5tSjMI7iD5zfjneTT"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Entidades.Dto;
|
||||||
|
public class AceptarContratoDto {
|
||||||
|
public long Idcontrato { get; set; }
|
||||||
|
public DateTime Fecha { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Entidades.Dto;
|
||||||
|
public class RechazarPreContrato {
|
||||||
|
public long Idcontrato { get; set; }
|
||||||
|
public DateTime Fecha { get; set; }
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
let {getContrato, onConfirm, onCancel, onClose, men
|
let {getContrato, onConfirm, onCancel, onClose, men
|
||||||
} : {
|
} : {
|
||||||
getContrato:(idcontrato:number)=>void,
|
getContrato:(idcontrato:number)=>void,
|
||||||
onConfirm:()=>void,
|
onConfirm:(idcontrato:number)=>void,
|
||||||
onCancel:()=>void,
|
onCancel:(idcontrato:number)=>void,
|
||||||
onClose:()=>void,
|
onClose:()=>void,
|
||||||
men: MensajeDto
|
men: MensajeDto
|
||||||
} = $props();
|
} = $props();
|
||||||
@@ -21,13 +21,15 @@
|
|||||||
|
|
||||||
function confirmar() {
|
function confirmar() {
|
||||||
if (leiContrato) {
|
if (leiContrato) {
|
||||||
onConfirm();
|
let idcontrato = Number(men.mensaje.split(" ").reverse()[0]);
|
||||||
|
onConfirm(idcontrato);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function rechazar() {
|
function rechazar() {
|
||||||
if (leiContrato) {
|
if (leiContrato) {
|
||||||
onCancel();
|
let idcontrato = Number(men.mensaje.split(" ").reverse()[0]);
|
||||||
|
onCancel(idcontrato);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
import { self } from "svelte/legacy";
|
import { self } from "svelte/legacy";
|
||||||
import ModalVeryAceptarContrato from "../Componentes/ModalVeryAceptarContrato.svelte";
|
import ModalVeryAceptarContrato from "../Componentes/ModalVeryAceptarContrato.svelte";
|
||||||
import { getRequest } from "@sveltejs/kit/node";
|
import { getRequest } from "@sveltejs/kit/node";
|
||||||
|
import { json } from "@sveltejs/kit";
|
||||||
|
|
||||||
const token = sessionStorage.getItem("token");
|
const token = sessionStorage.getItem("token");
|
||||||
let mensajes: MensajeDto[] = $state([]);
|
let mensajes: MensajeDto[] = $state([]);
|
||||||
@@ -320,7 +321,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let blob = await Blob(responce.body());
|
let blob = await responce.blob();
|
||||||
const blobUrl = URL.createObjectURL(blob);
|
const blobUrl = URL.createObjectURL(blob);
|
||||||
window.open(blobUrl, '_blank');
|
window.open(blobUrl, '_blank');
|
||||||
setTimeout(() => URL.revokeObjectURL(blobUrl), 100000);
|
setTimeout(() => URL.revokeObjectURL(blobUrl), 100000);
|
||||||
@@ -329,6 +330,74 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handlerechazarcontrato(idcontrato:number) {
|
||||||
|
if (idcontrato<=0){
|
||||||
|
modaldata="La idcontrato da 0 o menos comunicate con el administrador";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let rq = {
|
||||||
|
idcontrato:idcontrato,
|
||||||
|
fecha:Selmens.fecha,
|
||||||
|
}
|
||||||
|
const responce = await fetch($urlG+"/api/contratos/aceptarContrato", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
},
|
||||||
|
body: JSON.stringify(rq),
|
||||||
|
});
|
||||||
|
if (responce.ok){
|
||||||
|
let data = await responce.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
if (mostrarleidos) {
|
||||||
|
Leidos();
|
||||||
|
} else {
|
||||||
|
SinLeer();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = await responce.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
return;
|
||||||
|
} catch {
|
||||||
|
modaldata = "Fallo la request";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAceptarContrato(idcontrato:number) {
|
||||||
|
if (idcontrato<=0){
|
||||||
|
modaldata="La idcontrato da 0 o menos comunicate con el administrador";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const responce = await fetch($urlG+"/api/contratos/rechazarPreContrato?idcontrato="+idcontrato, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (responce.ok){
|
||||||
|
let data = await responce.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
if (mostrarleidos) {
|
||||||
|
Leidos();
|
||||||
|
} else {
|
||||||
|
SinLeer();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = await responce.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
return;
|
||||||
|
} catch {
|
||||||
|
modaldata = "Fallo la request";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<NavBarAutocompletable/>
|
<NavBarAutocompletable/>
|
||||||
@@ -344,7 +413,7 @@
|
|||||||
{:else if Selmens.accion == "Check y Contrato"}
|
{:else if Selmens.accion == "Check y Contrato"}
|
||||||
<ModalCheckYContrato {garantes} men={Selmens} onCancel={handleCancelPrecontrato} onClose={() => (Selmens.accion = "")} onConfirm={handleEnviarmensaje4}/>
|
<ModalCheckYContrato {garantes} men={Selmens} onCancel={handleCancelPrecontrato} onClose={() => (Selmens.accion = "")} onConfirm={handleEnviarmensaje4}/>
|
||||||
{:else if Selmens.accion == "Aceptar Contrato"}
|
{:else if Selmens.accion == "Aceptar Contrato"}
|
||||||
<ModalVeryAceptarContrato onClose={() => (Selmens.accion = "")} onConfirm={()=> ""} onCancel={()=>""} getContrato={ObtenerContrato} men={Selmens}/>
|
<ModalVeryAceptarContrato onClose={() => (Selmens.accion = "")} onConfirm={handleAceptarContrato} onCancel={handleCancelPrecontrato} getContrato={ObtenerContrato} men={Selmens}/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|||||||
@@ -81,8 +81,9 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
|||||||
x.Habilitado == 0 &&
|
x.Habilitado == 0 &&
|
||||||
x.Cancelado == 0);
|
x.Cancelado == 0);
|
||||||
|
|
||||||
if (contr == null) return false;
|
if (contr == null || contr.IdpropiedadNavigation == null) return false;
|
||||||
contr.Cancelado = 1;
|
contr.Cancelado = 1;
|
||||||
|
contr.IdpropiedadNavigation.Idestado = 1;
|
||||||
return Guardar(con);
|
return Guardar(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,4 +106,40 @@ public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
|||||||
contrato.UrlContrato = nuevoNombreArchivo;
|
contrato.UrlContrato = nuevoNombreArchivo;
|
||||||
return Guardar(con);
|
return Guardar(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AceptarContrato(long idcontrato) {
|
||||||
|
var con = Context;
|
||||||
|
Contrato? cont = con.Contratos
|
||||||
|
.Include(x=>x.Idcanons)
|
||||||
|
.Include(x=>x.Idpropiedad)
|
||||||
|
.FirstOrDefault(x=>x.Id ==idcontrato &&
|
||||||
|
x.Habilitado ==0 &&
|
||||||
|
x.Cancelado == 0);
|
||||||
|
|
||||||
|
if (cont == null || cont.IdpropiedadNavigation==null) return false;
|
||||||
|
|
||||||
|
cont.Habilitado = 1;
|
||||||
|
var fecha = cont.Fechainicio;
|
||||||
|
|
||||||
|
for (int i = 0; i < cont.MesesHastaAumento; i++) {
|
||||||
|
Canon can = new Canon{
|
||||||
|
Fecha = fecha.AddMonths(i),
|
||||||
|
Monto = cont.IdpropiedadNavigation.Monto,
|
||||||
|
Pagado = 0
|
||||||
|
};
|
||||||
|
can.Id = (con.Canons.Any()? con.Canons.Max(x=>x.Id) :0)+1;
|
||||||
|
|
||||||
|
cont.Idcanons.Add(can);
|
||||||
|
}
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CancelarPrecontrato(long idcontrato) {
|
||||||
|
var con = Context;
|
||||||
|
Contrato? cont = con.Contratos.Include(x=>x.Idpropiedad).FirstOrDefault(x=>x.Id ==idcontrato && x.Habilitado ==0);
|
||||||
|
if (cont == null|| cont.IdpropiedadNavigation==null) return false;
|
||||||
|
cont.Cancelado = 1;
|
||||||
|
cont.IdpropiedadNavigation.Idestado = 1;
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user