Refactor code formatting
This commit is contained in:
@@ -12,27 +12,31 @@ using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class VentaController:ControllerBase {
|
||||
public class VentaController : ControllerBase
|
||||
{
|
||||
|
||||
[HttpPost("api/venta/AceptarConsultaVenta")]
|
||||
public IActionResult AceptarConsultaVenta([FromHeader(Name="Auth")]string Auth, NotificacionMarcarLeidoDto dto) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
public IActionResult AceptarConsultaVenta([FromHeader(Name = "Auth")] string Auth, NotificacionMarcarLeidoDto dto)
|
||||
{
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 15);
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email"});
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) Unauthorized();
|
||||
if (cli.Email != dto.Email) return BadRequest(new {message = "El token de autorizacion no corresponde a tu usuario"});
|
||||
if (cli.Email != dto.Email) return BadRequest(new { message = "El token de autorizacion no corresponde a tu usuario" });
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
if (n == null) return BadRequest(new { message = "No se encuentra la notificacion"});
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
if (n == null) return BadRequest(new { message = "No se encuentra la notificacion" });
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(n.Idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No se encuentra una propiedad por ese id"});
|
||||
Venta? v = new Venta{
|
||||
if (prop == null) return BadRequest(new { message = "No se encuentra una propiedad por ese id" });
|
||||
Venta? v = new Venta
|
||||
{
|
||||
Fechainicio = DateTime.Now,
|
||||
IdVendedor = prop.Dnipropietario,
|
||||
IdComprador = n.Dniremitente,
|
||||
@@ -44,7 +48,8 @@ public class VentaController:ControllerBase {
|
||||
};
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.IniciarVenta(v, cli.Dni);
|
||||
if (ret){
|
||||
if (ret)
|
||||
{
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion")
|
||||
.SetMensaje("Debe Realizar el pago para que se registre el traspaso de la propiedad")
|
||||
@@ -56,25 +61,27 @@ public class VentaController:ControllerBase {
|
||||
.Build();
|
||||
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
}
|
||||
return ret?
|
||||
Ok(new { message = "Se inicio la venta"}):BadRequest(new { message ="fallo al iniciar la venta"});
|
||||
return ret ?
|
||||
Ok(new { message = "Se inicio la venta" }) : BadRequest(new { message = "fallo al iniciar la venta" });
|
||||
}
|
||||
|
||||
[HttpPost("api/venta/CancelarConsultaVenta")]
|
||||
public IActionResult CancelarConsultaVenta([FromHeader(Name="Auth")]string Auth, NotificacionMarcarLeidoDto dto) {
|
||||
public IActionResult CancelarConsultaVenta([FromHeader(Name = "Auth")] string Auth, NotificacionMarcarLeidoDto dto)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email"});
|
||||
if (dto.Email == "") return BadRequest(new { message = "Falta dato Email" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) Unauthorized();
|
||||
if (cli.Email != dto.Email) return BadRequest(new {message = "El token de autorizacion no corresponde a tu usuario"});
|
||||
if (cli.Email != dto.Email) return BadRequest(new { message = "El token de autorizacion no corresponde a tu usuario" });
|
||||
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(cli.Dni, dto.Fecha);
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
Notificacione? n = RepositorioNotificaciones.Singleton.ObtenerNotificacionPorKeys(cli.Dni, dto.Fecha);
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion")
|
||||
.SetMensaje("El propietario no quiere vender")
|
||||
@@ -84,90 +91,98 @@ public class VentaController:ControllerBase {
|
||||
.SetIdpropiedad(n.Idpropiedad)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
|
||||
|
||||
var ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
return ret ?
|
||||
Ok(new{message = "Se Envio una notificacion"}):BadRequest(new{message = "Fallo al Descartar Consulta"});
|
||||
Ok(new { message = "Se Envio una notificacion" }) : BadRequest(new { message = "Fallo al Descartar Consulta" });
|
||||
}
|
||||
|
||||
[HttpGet("/api/propiedad/EstaALaVenta")]
|
||||
public IActionResult EstaALaVenta([FromHeader(Name="Auth")]string Auth, int idprop=0) {
|
||||
public IActionResult EstaALaVenta([FromHeader(Name = "Auth")] string Auth, int idprop = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (idprop<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
if (idprop <= 0) return BadRequest(new { message = "No hay propiedades con id 0 o menor" });
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(idprop);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
return Ok(new { EstaAVenta = prop.Idestado ==4?true:false});
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id" });
|
||||
return Ok(new { EstaAVenta = prop.Idestado == 4 ? true : false });
|
||||
}
|
||||
|
||||
[HttpPut("/api/propiedad/setPropiedadAVenta")]
|
||||
public IActionResult setPropiedadAVenta([FromHeader(Name="Auth")]string Auth, SetVentaDto dto) {
|
||||
public IActionResult setPropiedadAVenta([FromHeader(Name = "Auth")] string Auth, SetVentaDto dto)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.iddivisa != 0 && dto.iddivisa!=1) return BadRequest(new { message = "no hay una divisa por esa id"});
|
||||
if (dto.idpropiedad<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
if (dto.monto<1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1"});
|
||||
if (dto.iddivisa != 0 && dto.iddivisa != 1) return BadRequest(new { message = "no hay una divisa por esa id" });
|
||||
if (dto.idpropiedad <= 0) return BadRequest(new { message = "No hay propiedades con id 0 o menor" });
|
||||
if (dto.monto < 1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id" });
|
||||
|
||||
if (cli.Dni != prop.Dnipropietario) return Unauthorized();
|
||||
|
||||
var ret = RepositorioVentas.Singleton.SetVenta(prop.Id, dto.monto, dto.iddivisa, cli.Dni);
|
||||
return ret?
|
||||
Ok(new { message = "Se puso la propiedad de venta"}) : BadRequest(new { message = "No se pudo poner a la Venta"});
|
||||
return ret ?
|
||||
Ok(new { message = "Se puso la propiedad de venta" }) : BadRequest(new { message = "No se pudo poner a la Venta" });
|
||||
}
|
||||
|
||||
[HttpPut("/api/propiedad/unsetPropiedadAVenta")]
|
||||
public IActionResult unsetPropiedadAVenta([FromHeader(Name="Auth")]string Auth, SetVentaDto dto) {
|
||||
public IActionResult unsetPropiedadAVenta([FromHeader(Name = "Auth")] string Auth, SetVentaDto dto)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (dto.iddivisa != 0 && dto.iddivisa!=1) return BadRequest(new { message = "no hay una divisa por esa id"});
|
||||
if (dto.idpropiedad<=0) return BadRequest(new { message = "No hay propiedades con id 0 o menor"});
|
||||
if (dto.monto<1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1"});
|
||||
|
||||
if (dto.iddivisa != 0 && dto.iddivisa != 1) return BadRequest(new { message = "no hay una divisa por esa id" });
|
||||
if (dto.idpropiedad <= 0) return BadRequest(new { message = "No hay propiedades con id 0 o menor" });
|
||||
if (dto.monto < 1) return BadRequest(new { message = "No se pueden hacer ventas por montos menores a 1" });
|
||||
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Propiedade? prop = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(dto.idpropiedad);
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id"});
|
||||
if (prop == null) return BadRequest(new { message = "No hay propiedades por ese id" });
|
||||
|
||||
if (cli.Dni != prop.Dnipropietario) return Unauthorized();
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.UnSetVenta(prop.Id, dto.monto, dto.iddivisa, cli.Dni);
|
||||
|
||||
return ret?
|
||||
Ok(new { message = "Se Bajo la propiedad de venta"}) : BadRequest(new { message = "No se pudo Bajar de venta"});
|
||||
return ret ?
|
||||
Ok(new { message = "Se Bajo la propiedad de venta" }) : BadRequest(new { message = "No se pudo Bajar de venta" });
|
||||
}
|
||||
|
||||
[HttpPost("/api/ventas/ejercerOpcionVenta")]
|
||||
public IActionResult EjercerOpcionVenta([FromHeader(Name="Auth")]string Auth, [FromQuery]long idcontrato=0) {
|
||||
public IActionResult EjercerOpcionVenta([FromHeader(Name = "Auth")] string Auth, [FromQuery] long idcontrato = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (idcontrato <= 0) return BadRequest(new { message = "No pueden hacer cotratos con id 0 o menor"});
|
||||
if (idcontrato <= 0) return BadRequest(new { message = "No pueden hacer cotratos con id 0 o menor" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioVentas.Singleton.ObtenerVentaPorContrato(idcontrato);
|
||||
if (cont == null || cont.IdventaNavigation == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||
if (cont.Tieneopcionventa == 0) return BadRequest(new { message = "No tiene opcion de venta"});
|
||||
if (puedeEjercer(cont) == false) return BadRequest(new { message = "No cumple con los requisitos para ejercer la opcion de compra"});
|
||||
if (cont == null || cont.IdventaNavigation == null) return BadRequest(new { message = "no hay un contrato por esa id" });
|
||||
if (cont.Tieneopcionventa == 0) return BadRequest(new { message = "No tiene opcion de venta" });
|
||||
if (puedeEjercer(cont) == false) return BadRequest(new { message = "No cumple con los requisitos para ejercer la opcion de compra" });
|
||||
|
||||
Venta venta = cont.IdventaNavigation;
|
||||
venta.IdVendedor = cont.Dnipropietario;
|
||||
@@ -177,31 +192,34 @@ public class VentaController:ControllerBase {
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.PatchVenta(venta, cli.Dni);
|
||||
|
||||
return ret?
|
||||
Ok(new { message = "Se ejercio la opcion de venta"}):
|
||||
BadRequest(new { message = "No se pude ejercer la opcion de venta"});
|
||||
return ret ?
|
||||
Ok(new { message = "Se ejercio la opcion de venta" }) :
|
||||
BadRequest(new { message = "No se pude ejercer la opcion de venta" });
|
||||
}
|
||||
|
||||
[HttpPost("/api/ventas/subirReciboPago")]
|
||||
public async Task<IActionResult> SubirRecibo([FromHeader(Name="Auth")]string Auth, IFormFile file, long idventa ) {
|
||||
public async Task<IActionResult> SubirRecibo([FromHeader(Name = "Auth")] string Auth, IFormFile file, long idventa)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
if (idventa <=0) return BadRequest(new { message = "Las id 0 o menor no son validas" });
|
||||
if (idventa <= 0) return BadRequest(new { message = "Las id 0 o menor no son validas" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Venta? venta = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta por esa id"});
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta por esa id" });
|
||||
|
||||
if (cli.Dni !=venta.IdComprador && cli.Dni != venta.IdVendedor) return Unauthorized();
|
||||
if (cli.Dni != venta.IdComprador && cli.Dni != venta.IdVendedor) return Unauthorized();
|
||||
|
||||
if (file == null) return BadRequest(new { message = "Debe subir un archivo." });
|
||||
if (file.ContentType != "application/pdf") return BadRequest(new { message = "El archivo debe ser un documento PDF." });
|
||||
@@ -209,39 +227,45 @@ public class VentaController:ControllerBase {
|
||||
|
||||
string nuevoNombreArchivo = $"id:{venta.Id}-comprador:{venta.IdComprador}-vendedor:{venta.IdVendedor}-idprop:{venta.Idpropiedad}.pdf";
|
||||
bool ret = await subirContrato(file, nuevoNombreArchivo);
|
||||
if(ret == false) return BadRequest(new {message = "No se pudo subir el archivo"});
|
||||
if (ret == false) return BadRequest(new { message = "No se pudo subir el archivo" });
|
||||
|
||||
ret = RepositorioVentas.Singleton.SetUrlRecibo(venta.Id, nuevoNombreArchivo, cli.Dni);
|
||||
if (ret == false) return BadRequest(new { message = "no se pudo guardar el nombre del archivo subido"});
|
||||
if (ret == false) return BadRequest(new { message = "no se pudo guardar el nombre del archivo subido" });
|
||||
|
||||
return Ok(new { message = "Se Subio el Recibo"});
|
||||
return Ok(new { message = "Se Subio el Recibo" });
|
||||
|
||||
}
|
||||
private readonly IMinioClient mc;
|
||||
public VentaController(IMinioClient minioClient) {
|
||||
public VentaController(IMinioClient minioClient)
|
||||
{
|
||||
mc = minioClient;
|
||||
if (mc == null){
|
||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json"))?? null;
|
||||
if (mc == null)
|
||||
{
|
||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json")) ?? null;
|
||||
if (mcon == null) throw new Exception();
|
||||
|
||||
mc = new MinioClient().WithCredentials(mcon.usr, mcon.scrt)
|
||||
.WithEndpoint("0.0.0.0:9000")
|
||||
.WithSSL(false)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
private async Task<bool> subirContrato(IFormFile f, string flname) {
|
||||
try {
|
||||
private async Task<bool> subirContrato(IFormFile f, string flname)
|
||||
{
|
||||
try
|
||||
{
|
||||
var buck = new BucketExistsArgs().WithBucket("alquilafacil");
|
||||
bool encontrado = await mc.BucketExistsAsync(buck).ConfigureAwait(false);
|
||||
|
||||
if(!encontrado){
|
||||
if (!encontrado)
|
||||
{
|
||||
var mb = new MakeBucketArgs().WithBucket("alquilafacil");
|
||||
await mc.MakeBucketAsync(mb).ConfigureAwait(false);
|
||||
}
|
||||
using (var stream = new MemoryStream()){
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await f.CopyToAsync(stream);
|
||||
stream.Position=0;
|
||||
stream.Position = 0;
|
||||
PutObjectArgs putbj = new PutObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(flname)
|
||||
@@ -251,118 +275,140 @@ public class VentaController:ControllerBase {
|
||||
await mc.PutObjectAsync(putbj);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e ) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Error.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("/api/ventas/verRecibo")]
|
||||
public IActionResult verRecibo([FromHeader(Name="Auth")]string Auth, long idventa=0){
|
||||
public IActionResult verRecibo([FromHeader(Name = "Auth")] string Auth, long idventa = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Venta? venta = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta con esa id"});
|
||||
if (venta == null) return BadRequest(new { message = "no hay una venta con esa id" });
|
||||
if (cli.Dni != venta.IdComprador && cli.Dni != venta.IdVendedor) return Unauthorized();
|
||||
|
||||
try{
|
||||
var memstream = new MemoryStream();
|
||||
try
|
||||
{
|
||||
var memstream = new MemoryStream();
|
||||
|
||||
var goa = new GetObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(venta.UrlRecibo)
|
||||
.WithCallbackStream(stream => {
|
||||
memstream.Position=0;
|
||||
.WithCallbackStream(stream =>
|
||||
{
|
||||
memstream.Position = 0;
|
||||
stream.CopyTo(memstream);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
mc.GetObjectAsync(goa).Wait();
|
||||
memstream.Position = 0;
|
||||
|
||||
|
||||
if (memstream.Length == 0) return BadRequest(new { message = "El archivo está vacío" });
|
||||
|
||||
|
||||
return File(memstream, "application/pdf", venta.UrlRecibo);
|
||||
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
catch (Exception 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" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost("/api/ventas/propietarioverifica")]
|
||||
public IActionResult PropietarioVerifica([FromHeader(Name="Auth")]string Auth, long idventa=0) {
|
||||
public IActionResult PropietarioVerifica([FromHeader(Name = "Auth")] string Auth, long idventa = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (ventas == null) return BadRequest(new { message ="No hay una venta con ese id"});
|
||||
if (ventas == null) return BadRequest(new { message = "No hay una venta con ese id" });
|
||||
if (ventas.IdVendedor != cli.Dni) return Unauthorized();
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.EfectuarVenta(idventa);
|
||||
return ret ? Ok(new { message = "Se traspaso la propiedad"}): BadRequest(new { message = ""});
|
||||
return ret ? Ok(new { message = "Se traspaso la propiedad" }) : BadRequest(new { message = "" });
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet("/api/venta")]
|
||||
public IActionResult ObtenerVenta([FromHeader(Name="Auth")]string Auth, long idventa=0) {
|
||||
public IActionResult ObtenerVenta([FromHeader(Name = "Auth")] string Auth, long idventa = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0"});
|
||||
if (idventa <= 0) return BadRequest(new { message = "No existen ventas validas para la id 0" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentaPorId(idventa);
|
||||
if (ventas == null) return BadRequest(new { message ="No hay una venta con ese id"});
|
||||
if (ventas.IdVendedor !=cli.Dni && ventas.IdComprador != cli.Dni) return Unauthorized();
|
||||
if (ventas == null) return BadRequest(new { message = "No hay una venta con ese id" });
|
||||
if (ventas.IdVendedor != cli.Dni && ventas.IdComprador != cli.Dni) return Unauthorized();
|
||||
|
||||
var v = new VentasDtoBuilder()
|
||||
.SetId(ventas.Id)
|
||||
.SetMonto(ventas.Monto)
|
||||
.SetDivisa(ventas.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(ventas.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{ventas.IdVendedorNavigation.Nombre} {ventas.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(ventas.IdVendedor??0)
|
||||
.SetNombreComprador($"{ventas.IdCompradorNavigation.Nombre} {ventas.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(ventas.IdComprador??0)
|
||||
.SetEstado(ventas.IdestadoNavigation.Descripcion??"")
|
||||
.SetId(ventas.Id)
|
||||
.SetMonto(ventas.Monto)
|
||||
.SetDivisa(ventas.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(ventas.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{ventas.IdVendedorNavigation.Nombre} {ventas.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(ventas.IdVendedor ?? 0)
|
||||
.SetNombreComprador($"{ventas.IdCompradorNavigation.Nombre} {ventas.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(ventas.IdComprador ?? 0)
|
||||
.SetEstado(ventas.IdestadoNavigation.Descripcion ?? "")
|
||||
.Build();
|
||||
|
||||
return Ok(new { data = v, iscomprador = (ventas.IdComprador==cli.Dni)?true:false,
|
||||
necesitaRecibo = ventas.UrlRecibo==null?true:false});
|
||||
return Ok(new
|
||||
{
|
||||
data = v,
|
||||
iscomprador = (ventas.IdComprador == cli.Dni) ? true : false,
|
||||
necesitaRecibo = ventas.UrlRecibo == null ? true : false
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("/api/ventas")]
|
||||
public IActionResult ObtenerVentas([FromHeader(Name="Auth")]string Auth) {
|
||||
public IActionResult ObtenerVentas([FromHeader(Name = "Auth")] string Auth)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
@@ -371,20 +417,21 @@ public class VentaController:ControllerBase {
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
var ventas = RepositorioVentas.Singleton.ObtenerVentasPorDni(cli.Dni);
|
||||
if (ventas == null) return BadRequest(new { message ="no estas involucrado en ninguna venta o compra"});
|
||||
if (ventas == null) return BadRequest(new { message = "no estas involucrado en ninguna venta o compra" });
|
||||
|
||||
List<VentasDto> lista = new();
|
||||
foreach (var i in ventas) {
|
||||
foreach (var i in ventas)
|
||||
{
|
||||
var v = new VentasDtoBuilder()
|
||||
.SetId(i.Id)
|
||||
.SetMonto(i.Monto)
|
||||
.SetDivisa(i.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{i.IdVendedorNavigation.Nombre} {i.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(i.IdVendedor??0)
|
||||
.SetNombreComprador($"{i.IdCompradorNavigation.Nombre} {i.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(i.IdComprador??0)
|
||||
.SetEstado(i.IdestadoNavigation.Descripcion??"")
|
||||
.SetId(i.Id)
|
||||
.SetMonto(i.Monto)
|
||||
.SetDivisa(i.IddivisaNavigation.Signo)
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetNombreVendedor($"{i.IdVendedorNavigation.Nombre} {i.IdVendedorNavigation.Apellido}")
|
||||
.SetIdVendedor(i.IdVendedor ?? 0)
|
||||
.SetNombreComprador($"{i.IdCompradorNavigation.Nombre} {i.IdCompradorNavigation.Apellido}")
|
||||
.SetIdComprador(i.IdComprador ?? 0)
|
||||
.SetEstado(i.IdestadoNavigation.Descripcion ?? "")
|
||||
.Build();
|
||||
lista.Add(v);
|
||||
}
|
||||
@@ -392,43 +439,51 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[HttpGet("/api/opcionventa")]
|
||||
public IActionResult ObtenerDto([FromHeader(Name="Auth")]string Auth, long idcontrato=0) {
|
||||
public IActionResult ObtenerDto([FromHeader(Name = "Auth")] string Auth, long idcontrato = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0"});
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioVentas.Singleton.ObtenerVentaPorContrato(idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"});
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id" });
|
||||
|
||||
var dto = new OpcionVentaDtoBuilder()
|
||||
.SetId(cont.Idventa??0)
|
||||
.SetId(cont.Idventa ?? 0)
|
||||
.SetMonto(cont.IdventaNavigation.Monto)
|
||||
.SetDivisa(cont.IdventaNavigation.IddivisaNavigation.Signo)
|
||||
.SetEnOrden(puedeEjercer(cont))
|
||||
.SetFueEjercido(cont.IdventaNavigation.Idestado??0)
|
||||
.SetFueEjercido(cont.IdventaNavigation.Idestado ?? 0)
|
||||
.Build();
|
||||
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
private bool puedeEjercer(Contrato c) {
|
||||
private bool puedeEjercer(Contrato c)
|
||||
{
|
||||
bool ret = c.Idcanons.All(x => x.Pagado == 1);
|
||||
|
||||
if (ret) {
|
||||
if (ret)
|
||||
{
|
||||
var canonConFechaMasTardia = c.Idcanons.OrderByDescending(x => x.Fecha).FirstOrDefault();
|
||||
|
||||
if (canonConFechaMasTardia != null && canonConFechaMasTardia.Fecha.Year >= DateTime.Now.Year
|
||||
&& canonConFechaMasTardia.Fecha.Month >= DateTime.Now.Month) {
|
||||
if (canonConFechaMasTardia != null && canonConFechaMasTardia.Fecha.Year >= DateTime.Now.Year
|
||||
&& canonConFechaMasTardia.Fecha.Month >= DateTime.Now.Month)
|
||||
{
|
||||
ret = true;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
@@ -437,24 +492,27 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[HttpGet("/api/contrato/tieneopcionventa")]
|
||||
public IActionResult TieneOpcionVenta([FromHeader(Name="Auth")]string Auth, long idcontrato=0) {
|
||||
public IActionResult TieneOpcionVenta([FromHeader(Name = "Auth")] string Auth, long idcontrato = 0)
|
||||
{
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
if (validacion1 == false)
|
||||
{
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
if (validacion1 == false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0"});
|
||||
|
||||
if (idcontrato == 0) return BadRequest(new { message = "No existen contatos validos para la id 0" });
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli == null) return Unauthorized();
|
||||
|
||||
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(idcontrato);
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id"});
|
||||
if (cont.Dniinquilino !=cli.Dni && cont.Dnipropietario != cli.Dni) return Unauthorized();
|
||||
if (cont == null) return BadRequest(new { message = "No hay un contrato por esa id" });
|
||||
if (cont.Dniinquilino != cli.Dni && cont.Dnipropietario != cli.Dni) return Unauthorized();
|
||||
|
||||
return Ok( new { message = cont.Tieneopcionventa});
|
||||
return Ok(new { message = cont.Tieneopcionventa });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user