falta testear
This commit is contained in:
@@ -275,7 +275,7 @@ public class ContratoController: ControllerBase {
|
||||
}
|
||||
|
||||
[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("");
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
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";
|
||||
try{
|
||||
using( var memstream = new MemoryStream()){
|
||||
var memstream = new MemoryStream();
|
||||
|
||||
var goa = new GetObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(nuevoNombreArchivo)
|
||||
.WithCallbackStream(async stream => {
|
||||
.WithCallbackStream(stream => {
|
||||
memstream.Position=0;
|
||||
await stream.CopyToAsync(memstream);
|
||||
stream.CopyTo(memstream);
|
||||
});
|
||||
|
||||
await mc.GetObjectAsync(goa);
|
||||
mc.GetObjectAsync(goa).Wait();
|
||||
memstream.Position = 0;
|
||||
|
||||
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){
|
||||
Console.Error.WriteLine(e);
|
||||
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")]
|
||||
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();
|
||||
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"});
|
||||
|
||||
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();
|
||||
|
||||
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"});
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user