refactor
This commit is contained in:
@@ -15,15 +15,19 @@ using Modelo;
|
|||||||
namespace AlquilaFacil.Controllers;
|
namespace AlquilaFacil.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class ContratoController: ControllerBase {
|
public class ContratoController : ControllerBase
|
||||||
|
{
|
||||||
|
|
||||||
[HttpPost("api/contrato/GenerarRecibo")]
|
[HttpPost("api/contrato/GenerarRecibo")]
|
||||||
public ActionResult GenerarRecibo([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto, bool html= true) {
|
public ActionResult GenerarRecibo([FromHeader(Name = "Auth")] string Auth, MarcarPagoDto dto, bool html = true)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false){
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) {
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,10 +56,13 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
var dof = new DocumentoFacade();
|
var dof = new DocumentoFacade();
|
||||||
MemoryStream? memstr = new();
|
MemoryStream? memstr = new();
|
||||||
if (html){
|
if (html)
|
||||||
|
{
|
||||||
dof.GenerarHtml(cdb, can.IdreciboNavigation, memstr);
|
dof.GenerarHtml(cdb, can.IdreciboNavigation, memstr);
|
||||||
return File(memstr, "text/html", "Recibo.html");
|
return File(memstr, "text/html", "Recibo.html");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dof.GenerarPdf(cdb, can.IdreciboNavigation, memstr);
|
dof.GenerarPdf(cdb, can.IdreciboNavigation, memstr);
|
||||||
return File(memstr, "application/pdf", "Recibo.pdf");
|
return File(memstr, "application/pdf", "Recibo.pdf");
|
||||||
}
|
}
|
||||||
@@ -63,7 +70,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/marcarPago")]
|
[HttpPost("api/contratos/marcarPago")]
|
||||||
public IActionResult marcarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) {
|
public IActionResult marcarPago([FromHeader(Name = "Auth")] string Auth, MarcarPagoDto dto)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -80,7 +88,8 @@ public class ContratoController: ControllerBase {
|
|||||||
Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
||||||
if (c == null) return BadRequest(new { message = "no hay un canon por esa id" });
|
if (c == null) return BadRequest(new { message = "no hay un canon por esa id" });
|
||||||
|
|
||||||
Recibo re = new Recibo{
|
Recibo re = new Recibo
|
||||||
|
{
|
||||||
Monto = c.Monto,
|
Monto = c.Monto,
|
||||||
Fecha = DateTime.Now,
|
Fecha = DateTime.Now,
|
||||||
};
|
};
|
||||||
@@ -92,7 +101,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/realizarPago")]
|
[HttpPost("api/contratos/realizarPago")]
|
||||||
public IActionResult realizarPago([FromHeader(Name="Auth")]string Auth, MarcarPagoDto dto) {
|
public IActionResult realizarPago([FromHeader(Name = "Auth")] string Auth, MarcarPagoDto dto)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -109,7 +119,8 @@ public class ContratoController: ControllerBase {
|
|||||||
Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
Canon? c = RepositorioCanons.Singleton.ObtenerCanonContrato(dto.fecha, dto.Idcontrato);
|
||||||
if (c == null) return BadRequest(new { message = "no hay un canon por esa id" });
|
if (c == null) return BadRequest(new { message = "no hay un canon por esa id" });
|
||||||
|
|
||||||
Recibo re = new Recibo{
|
Recibo re = new Recibo
|
||||||
|
{
|
||||||
Monto = c.Monto,
|
Monto = c.Monto,
|
||||||
Fecha = DateTime.Now,
|
Fecha = DateTime.Now,
|
||||||
};
|
};
|
||||||
@@ -120,7 +131,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/crearcanons")]
|
[HttpPost("api/contratos/crearcanons")]
|
||||||
public IActionResult crearCanons([FromHeader(Name="Auth")]string Auth, CrearCanonsDto dto){
|
public IActionResult crearCanons([FromHeader(Name = "Auth")] string Auth, CrearCanonsDto dto)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -139,12 +151,15 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/canon")]
|
[HttpGet("api/contratos/canon")]
|
||||||
public ActionResult getCanons([FromHeader(Name="Auth")]string Auth, int id = 0) {
|
public ActionResult getCanons([FromHeader(Name = "Auth")] string Auth, int id = 0)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false){
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) {
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +178,8 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
List<CanonDto> d = new();
|
List<CanonDto> d = new();
|
||||||
|
|
||||||
foreach (var i in list) {
|
foreach (var i in list)
|
||||||
|
{
|
||||||
var c = new CanonDtoBuilder()
|
var c = new CanonDtoBuilder()
|
||||||
.SetId(i.Id)
|
.SetId(i.Id)
|
||||||
.SetPago(i.Idrecibo == null ? false : true)
|
.SetPago(i.Idrecibo == null ? false : true)
|
||||||
@@ -179,7 +195,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/propietario")]
|
[HttpGet("api/contratos/propietario")]
|
||||||
public IActionResult ObtenerContratosPorPropietario([FromHeader(Name="Auth")]string Auth) {
|
public IActionResult ObtenerContratosPorPropietario([FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -190,7 +207,8 @@ public class ContratoController: ControllerBase {
|
|||||||
var list = RepositorioContratos.Singleton.ObtenerContratosDePropietario(cli.Dni);
|
var list = RepositorioContratos.Singleton.ObtenerContratosDePropietario(cli.Dni);
|
||||||
|
|
||||||
List<ContratoDto> dtos = new();
|
List<ContratoDto> dtos = new();
|
||||||
foreach (var i in list) {
|
foreach (var i in list)
|
||||||
|
{
|
||||||
if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null
|
if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null
|
||||||
|| i.DnipropietarioNavigation == null) continue;
|
|| i.DnipropietarioNavigation == null) continue;
|
||||||
|
|
||||||
@@ -209,7 +227,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contrato/propietario")]
|
[HttpGet("api/contrato/propietario")]
|
||||||
public IActionResult ObtenerContratoPorPropietarioPorId([FromHeader(Name="Auth")]string Auth, int id=0) {
|
public IActionResult ObtenerContratoPorPropietarioPorId([FromHeader(Name = "Auth")] string Auth, int id = 0)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -242,7 +261,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/inquilino")]
|
[HttpGet("api/contratos/inquilino")]
|
||||||
public IActionResult ObtenerContratosPorInquilino([FromHeader(Name="Auth")]string Auth) {
|
public IActionResult ObtenerContratosPorInquilino([FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -253,7 +273,8 @@ public class ContratoController: ControllerBase {
|
|||||||
var list = RepositorioContratos.Singleton.ObtenerContratosDeInquilino(cli.Dni);
|
var list = RepositorioContratos.Singleton.ObtenerContratosDeInquilino(cli.Dni);
|
||||||
|
|
||||||
List<ContratoDto> dtos = new();
|
List<ContratoDto> dtos = new();
|
||||||
foreach (var i in list) {
|
foreach (var i in list)
|
||||||
|
{
|
||||||
if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null
|
if (i.DniinquilinoNavigation == null || i.IdpropiedadNavigation == null
|
||||||
|| i.DnipropietarioNavigation == null) continue;
|
|| i.DnipropietarioNavigation == null) continue;
|
||||||
|
|
||||||
@@ -272,7 +293,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contrato/inquilino")]
|
[HttpGet("api/contrato/inquilino")]
|
||||||
public IActionResult ObtenerContratoPorInquilinoPorId([FromHeader(Name="Auth")]string Auth, int id=0) {
|
public IActionResult ObtenerContratoPorInquilinoPorId([FromHeader(Name = "Auth")] string Auth, int id = 0)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -305,7 +327,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/precontrato")]
|
[HttpPost("api/contratos/precontrato")]
|
||||||
public IActionResult IniciarPrecontrato([FromHeader(Name = "Auth")]string Auth, [FromBody] PrecontratoDto dto) {
|
public IActionResult IniciarPrecontrato([FromHeader(Name = "Auth")] string Auth, [FromBody] PrecontratoDto dto)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -351,10 +374,14 @@ public class ContratoController: ControllerBase {
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bool ret;
|
bool ret;
|
||||||
if (dto.TieneOpcionVenta==false){
|
if (dto.TieneOpcionVenta == false)
|
||||||
|
{
|
||||||
ret = RepositorioContratos.Singleton.CargaPrecontrato(cli.Dni, precontrato, notificacion);
|
ret = RepositorioContratos.Singleton.CargaPrecontrato(cli.Dni, precontrato, notificacion);
|
||||||
} else {
|
}
|
||||||
Venta v = new Venta{
|
else
|
||||||
|
{
|
||||||
|
Venta v = new Venta
|
||||||
|
{
|
||||||
Idestado = 1,
|
Idestado = 1,
|
||||||
Iddivisa = dto.iddivisa,
|
Iddivisa = dto.iddivisa,
|
||||||
Monto = dto.MontoOpcion,
|
Monto = dto.MontoOpcion,
|
||||||
@@ -362,7 +389,8 @@ public class ContratoController: ControllerBase {
|
|||||||
ret = RepositorioContratos.Singleton.CargaPrecontratoOpcionVenta(precontrato, notificacion, v, cli.Dni);
|
ret = RepositorioContratos.Singleton.CargaPrecontratoOpcionVenta(precontrato, notificacion, v, cli.Dni);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret)
|
||||||
|
{
|
||||||
ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion));
|
ret = RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, DateTime.Parse(dto.fechaprimernotificacion));
|
||||||
}
|
}
|
||||||
return (ret) ?
|
return (ret) ?
|
||||||
@@ -371,7 +399,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/contratos/addGarantes")]
|
[HttpPut("api/contratos/addGarantes")]
|
||||||
public IActionResult AddGarantes([FromHeader(Name = "Auth")]string Auth, AltaGarantesDto dto) {
|
public IActionResult AddGarantes([FromHeader(Name = "Auth")] string Auth, AltaGarantesDto 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();
|
||||||
@@ -389,14 +418,16 @@ public class ContratoController: ControllerBase {
|
|||||||
Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorIdPropiedad(dto.Idpropiedad);
|
Cliente? propi = RepositorioPropietario.Singleton.ObtenerPropietarioPorIdPropiedad(dto.Idpropiedad);
|
||||||
if (propi == null) return BadRequest(new { message = "No se encuentra el propietario de la propiedad" });
|
if (propi == null) return BadRequest(new { message = "No se encuentra el propietario de la propiedad" });
|
||||||
|
|
||||||
foreach (var i in dto.garantes) {
|
foreach (var i in dto.garantes)
|
||||||
|
{
|
||||||
string validacion3 = ValidarDtoGarante(i);
|
string validacion3 = ValidarDtoGarante(i);
|
||||||
if (validacion3 != "") return BadRequest(new { message = validacion3 });
|
if (validacion3 != "") return BadRequest(new { message = validacion3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Garante> gar = new();
|
List<Garante> gar = new();
|
||||||
|
|
||||||
foreach (var i in dto.garantes) {
|
foreach (var i in dto.garantes)
|
||||||
|
{
|
||||||
Garante g = new GaranteBuilder()
|
Garante g = new GaranteBuilder()
|
||||||
.SetNombre(i.Nombre)
|
.SetNombre(i.Nombre)
|
||||||
.SetApellido(i.Apellido)
|
.SetApellido(i.Apellido)
|
||||||
@@ -412,7 +443,8 @@ public class ContratoController: ControllerBase {
|
|||||||
if (contr == null) return BadRequest(new { message = "No existe el contrato o ya fue activado" });
|
if (contr == null) return BadRequest(new { message = "No existe el contrato o ya fue activado" });
|
||||||
|
|
||||||
var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad, cli.Dni);
|
var ret = RepositorioContratos.Singleton.CargaGarantes(gar, dto.EmailInquilino, dto.Idpropiedad, cli.Dni);
|
||||||
if (ret) {
|
if (ret)
|
||||||
|
{
|
||||||
Console.WriteLine(dto.fecha);
|
Console.WriteLine(dto.fecha);
|
||||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.fecha);
|
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.fecha);
|
||||||
|
|
||||||
@@ -432,7 +464,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/contratos/cancelar")]
|
[HttpPut("api/contratos/cancelar")]
|
||||||
public IActionResult CancelarPrecontrato([FromHeader(Name = "Auth")]string Auth, CancelarPrecontratoDto dto) {
|
public IActionResult CancelarPrecontrato([FromHeader(Name = "Auth")] string Auth, CancelarPrecontratoDto dto)
|
||||||
|
{
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -455,10 +488,12 @@ public class ContratoController: ControllerBase {
|
|||||||
if (inq == null) return BadRequest(new { message = "No hay un inquilino por ese email" });
|
if (inq == null) return BadRequest(new { message = "No hay un inquilino por ese email" });
|
||||||
|
|
||||||
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad, cli.Dni);
|
var ret = RepositorioContratos.Singleton.CancelarPrecontrato(dto.EmailInquilino, dto.idpropiedad, cli.Dni);
|
||||||
if (ret) {
|
if (ret)
|
||||||
|
{
|
||||||
prop.Idestado = 1;
|
prop.Idestado = 1;
|
||||||
ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop, pro.Dni);
|
ret = RepositorioPropiedades.Singleton.PatchPropiedad(prop, pro.Dni);
|
||||||
if (ret){
|
if (ret)
|
||||||
|
{
|
||||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(pro.Dni, dto.fecha);
|
RepositorioNotificaciones.Singleton.MarcarComoLeido(pro.Dni, dto.fecha);
|
||||||
var noti = new NotificacioneBuilder()
|
var noti = new NotificacioneBuilder()
|
||||||
.SetAccion("ContratoCancelado")
|
.SetAccion("ContratoCancelado")
|
||||||
@@ -470,21 +505,29 @@ public class ContratoController: ControllerBase {
|
|||||||
.SetLeido(false)
|
.SetLeido(false)
|
||||||
.Build();
|
.Build();
|
||||||
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||||
if (ret){
|
if (ret)
|
||||||
|
{
|
||||||
return Ok(new { message = "Se cancelo el precontrato" });
|
return Ok(new { message = "Se cancelo el precontrato" });
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return Ok(new { message = "Se cancelo el precontrato, pero no se pudo notificar al inquilino" });
|
return Ok(new { message = "Se cancelo el precontrato, pero no se pudo notificar al inquilino" });
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return BadRequest(new { message = "No se pudo setear la propiedad como Disponible en busqueda" });
|
return BadRequest(new { message = "No se pudo setear la propiedad como Disponible en busqueda" });
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return BadRequest(new { message = "Se fallo al intentar cancelar el precontrato" });
|
return BadRequest(new { message = "Se fallo al intentar cancelar el precontrato" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/precontrato/listaGarantes")]
|
[HttpGet("api/contratos/precontrato/listaGarantes")]
|
||||||
public IActionResult ObtenerListaGarantes([FromHeader(Name = "Auth")]string Auth, long idcontrato = 0, [FromQuery] string EmailPropietario = "" ) {
|
public IActionResult ObtenerListaGarantes([FromHeader(Name = "Auth")] string Auth, long idcontrato = 0, [FromQuery] string EmailPropietario = "")
|
||||||
|
{
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -498,7 +541,8 @@ public class ContratoController: ControllerBase {
|
|||||||
if (contr == null) return BadRequest(new { message = "No hay un precontrato por esa id" });
|
if (contr == null) return BadRequest(new { message = "No hay un precontrato por esa id" });
|
||||||
|
|
||||||
LinkedList<GaranteDto> list = new();
|
LinkedList<GaranteDto> list = new();
|
||||||
foreach (var i in contr.Idgarantes) {
|
foreach (var i in contr.Idgarantes)
|
||||||
|
{
|
||||||
list.AddFirst(new GaranteDtoBuilder()
|
list.AddFirst(new GaranteDtoBuilder()
|
||||||
.SetCelular(i.Celular)
|
.SetCelular(i.Celular)
|
||||||
.SetDni(i.Dni)
|
.SetDni(i.Dni)
|
||||||
@@ -512,9 +556,11 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly IMinioClient mc;
|
private readonly IMinioClient mc;
|
||||||
public ContratoController(IMinioClient minioClient) {
|
public ContratoController(IMinioClient minioClient)
|
||||||
|
{
|
||||||
mc = minioClient;
|
mc = minioClient;
|
||||||
if (mc == null){
|
if (mc == null)
|
||||||
|
{
|
||||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json")) ?? null;
|
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json")) ?? null;
|
||||||
if (mcon == null) throw new Exception();
|
if (mcon == null) throw new Exception();
|
||||||
|
|
||||||
@@ -526,7 +572,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/subirContrato")]
|
[HttpPost("api/contratos/subirContrato")]
|
||||||
public async Task<IActionResult> subirContrato([FromHeader(Name = "Auth")]string Auth, [FromForm]long idcontrato, [FromForm]DateTime ubicarnotificacion, IFormFile contrato) {
|
public async Task<IActionResult> subirContrato([FromHeader(Name = "Auth")] string Auth, [FromForm] long idcontrato, [FromForm] DateTime ubicarnotificacion, IFormFile contrato)
|
||||||
|
{
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest("");
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -535,7 +582,8 @@ public class ContratoController: ControllerBase {
|
|||||||
Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato);
|
Contrato? contr = RepositorioContratos.Singleton.ObtenerPreContratoPorId(idcontrato);
|
||||||
if (contr == null) return BadRequest(new { message = "No hay precontrato por esa id" });
|
if (contr == null) return BadRequest(new { message = "No hay precontrato por esa id" });
|
||||||
if (contr.Dniinquilino == 0 || contr.Dnipropietario == 0 || contr.Idpropiedad == 0 ||
|
if (contr.Dniinquilino == 0 || contr.Dnipropietario == 0 || contr.Idpropiedad == 0 ||
|
||||||
contr.Dniinquilino == null || contr.Dnipropietario == null || contr.Idpropiedad == null) {
|
contr.Dniinquilino == null || contr.Dnipropietario == null || contr.Idpropiedad == null)
|
||||||
|
{
|
||||||
return BadRequest(new { message = "Estan mal cargados los datos del precontrato comunicate con un administrador" });
|
return BadRequest(new { message = "Estan mal cargados los datos del precontrato comunicate con un administrador" });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,10 +621,12 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
[HttpGet("api/contrato/DocumentoFinal")]
|
[HttpGet("api/contrato/DocumentoFinal")]
|
||||||
public IActionResult ObtenerContratoFinal ([FromHeader(Name = "Auth")]string Auth, [FromQuery]long idcontrato) {
|
public IActionResult ObtenerContratoFinal([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){
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
}
|
}
|
||||||
@@ -590,13 +640,15 @@ public class ContratoController: ControllerBase {
|
|||||||
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token" });
|
if (cli == null) return BadRequest(new { message = "No hay un cliente por ese token" });
|
||||||
if (cli.Dni != contr.Dniinquilino && cli.Dni != contr.Dnipropietario) return BadRequest(new { message = "El token no corresponde con el del inquilino" });
|
if (cli.Dni != contr.Dniinquilino && cli.Dni != contr.Dnipropietario) return BadRequest(new { message = "El token no corresponde con el del inquilino" });
|
||||||
|
|
||||||
try{
|
try
|
||||||
|
{
|
||||||
var memstream = new MemoryStream();
|
var memstream = new MemoryStream();
|
||||||
|
|
||||||
var goa = new GetObjectArgs()
|
var goa = new GetObjectArgs()
|
||||||
.WithBucket("alquilafacil")
|
.WithBucket("alquilafacil")
|
||||||
.WithObject(contr.UrlContrato)
|
.WithObject(contr.UrlContrato)
|
||||||
.WithCallbackStream(stream => {
|
.WithCallbackStream(stream =>
|
||||||
|
{
|
||||||
memstream.Position = 0;
|
memstream.Position = 0;
|
||||||
stream.CopyTo(memstream);
|
stream.CopyTo(memstream);
|
||||||
});
|
});
|
||||||
@@ -608,17 +660,21 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
return File(memstream, "application/pdf", contr.UrlContrato);
|
return File(memstream, "application/pdf", contr.UrlContrato);
|
||||||
|
|
||||||
} 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" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contrato/getdocumento")]
|
[HttpGet("api/contrato/getdocumento")]
|
||||||
public 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){
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
}
|
}
|
||||||
@@ -633,13 +689,15 @@ public class ContratoController: ControllerBase {
|
|||||||
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino" });
|
if (cli.Dni != contr.Dniinquilino) return BadRequest(new { message = "El token no corresponde con el del inquilino" });
|
||||||
|
|
||||||
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
|
||||||
|
{
|
||||||
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(stream => {
|
.WithCallbackStream(stream =>
|
||||||
|
{
|
||||||
memstream.Position = 0;
|
memstream.Position = 0;
|
||||||
stream.CopyTo(memstream);
|
stream.CopyTo(memstream);
|
||||||
});
|
});
|
||||||
@@ -651,7 +709,9 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
return File(memstream, "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" });
|
||||||
}
|
}
|
||||||
@@ -659,7 +719,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/aceptarContrato")]
|
[HttpPost("api/contratos/aceptarContrato")]
|
||||||
public IActionResult AceptarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] AceptarContratoDto dto){
|
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();
|
||||||
@@ -696,7 +757,8 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/contratos/rechazarPreContrato")]
|
[HttpPut("api/contratos/rechazarPreContrato")]
|
||||||
public IActionResult CancelarContrato([FromHeader(Name = "Auth")]string Auth, [FromBody] RechazarPreContrato dto ) {
|
public IActionResult CancelarContrato([FromHeader(Name = "Auth")] string Auth, [FromBody] RechazarPreContrato 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();
|
||||||
@@ -730,16 +792,20 @@ public class ContratoController: ControllerBase {
|
|||||||
BadRequest(new { message = "No se pudo cancelar" });
|
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)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
var buck = new BucketExistsArgs().WithBucket("alquilafacil");
|
var buck = new BucketExistsArgs().WithBucket("alquilafacil");
|
||||||
bool encontrado = await mc.BucketExistsAsync(buck).ConfigureAwait(false);
|
bool encontrado = await mc.BucketExistsAsync(buck).ConfigureAwait(false);
|
||||||
|
|
||||||
if(!encontrado){
|
if (!encontrado)
|
||||||
|
{
|
||||||
var mb = new MakeBucketArgs().WithBucket("alquilafacil");
|
var mb = new MakeBucketArgs().WithBucket("alquilafacil");
|
||||||
await mc.MakeBucketAsync(mb).ConfigureAwait(false);
|
await mc.MakeBucketAsync(mb).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
using (var stream = new MemoryStream()){
|
using (var stream = new MemoryStream())
|
||||||
|
{
|
||||||
await f.CopyToAsync(stream);
|
await f.CopyToAsync(stream);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
PutObjectArgs putbj = new PutObjectArgs()
|
PutObjectArgs putbj = new PutObjectArgs()
|
||||||
@@ -751,14 +817,17 @@ public class ContratoController: ControllerBase {
|
|||||||
await mc.PutObjectAsync(putbj);
|
await mc.PutObjectAsync(putbj);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e ) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
Console.Error.WriteLine(e.Message);
|
Console.Error.WriteLine(e.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/garantes")]
|
[HttpGet("api/contratos/garantes")]
|
||||||
public IActionResult ObtenerGarantes([FromHeader(Name ="Auth")] string Auth, int idcontrato) {
|
public IActionResult ObtenerGarantes([FromHeader(Name = "Auth")] string Auth, int idcontrato)
|
||||||
|
{
|
||||||
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest();
|
if (String.IsNullOrWhiteSpace(Auth)) return BadRequest();
|
||||||
if (idcontrato <= 0) return BadRequest();
|
if (idcontrato <= 0) return BadRequest();
|
||||||
|
|
||||||
@@ -772,7 +841,8 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
var list = cont.Idgarantes;
|
var list = cont.Idgarantes;
|
||||||
List<GaranteDto> l = new();
|
List<GaranteDto> l = new();
|
||||||
foreach (var i in list) {
|
foreach (var i in list)
|
||||||
|
{
|
||||||
l.Add(new GaranteDtoBuilder()
|
l.Add(new GaranteDtoBuilder()
|
||||||
.SetCelular(i.Celular)
|
.SetCelular(i.Celular)
|
||||||
.SetDni(i.Dni)
|
.SetDni(i.Dni)
|
||||||
@@ -785,7 +855,8 @@ public class ContratoController: ControllerBase {
|
|||||||
return Ok(l);
|
return Ok(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ValidarCancelarDto(CancelarPrecontratoDto dto) {
|
private string ValidarCancelarDto(CancelarPrecontratoDto dto)
|
||||||
|
{
|
||||||
if (dto == null) return "dto nulo";
|
if (dto == null) return "dto nulo";
|
||||||
string ret = "";
|
string ret = "";
|
||||||
|
|
||||||
@@ -796,7 +867,8 @@ public class ContratoController: ControllerBase {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ValidarDtoGarante(GaranteDto g) {
|
private string ValidarDtoGarante(GaranteDto g)
|
||||||
|
{
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (g == null) return "dto nulo";
|
if (g == null) return "dto nulo";
|
||||||
|
|
||||||
@@ -809,7 +881,8 @@ public class ContratoController: ControllerBase {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ValidarDtoAltaGarantes(AltaGarantesDto dto){
|
private string ValidarDtoAltaGarantes(AltaGarantesDto dto)
|
||||||
|
{
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (dto == null) return "dto nulo";
|
if (dto == null) return "dto nulo";
|
||||||
|
|
||||||
@@ -819,7 +892,8 @@ public class ContratoController: ControllerBase {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
private string ValidarDtoPrecontrato( PrecontratoDto dto) {
|
private string ValidarDtoPrecontrato(PrecontratoDto dto)
|
||||||
|
{
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (dto == null) return "dto nulo";
|
if (dto == null) return "dto nulo";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user