v2 ing soft #89
@@ -12,12 +12,15 @@ 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" });
|
||||
@@ -32,7 +35,8 @@ public class VentaController:ControllerBase {
|
||||
|
||||
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{
|
||||
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")
|
||||
@@ -61,9 +66,11 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
@@ -91,9 +98,11 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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" });
|
||||
@@ -104,9 +113,11 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
@@ -128,9 +139,11 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
||||
@@ -154,9 +167,11 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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" });
|
||||
@@ -183,12 +198,15 @@ public class VentaController:ControllerBase {
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
@@ -218,9 +236,11 @@ public class VentaController:ControllerBase {
|
||||
|
||||
}
|
||||
private readonly IMinioClient mc;
|
||||
public VentaController(IMinioClient minioClient) {
|
||||
public VentaController(IMinioClient minioClient)
|
||||
{
|
||||
mc = minioClient;
|
||||
if (mc == null){
|
||||
if (mc == null)
|
||||
{
|
||||
MinioConfigcus? mcon = JsonSerializer.Deserialize<MinioConfigcus>(System.IO.File.ReadAllText("./settings.json")) ?? null;
|
||||
if (mcon == null) throw new Exception();
|
||||
|
||||
@@ -230,16 +250,20 @@ public class VentaController:ControllerBase {
|
||||
.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;
|
||||
PutObjectArgs putbj = new PutObjectArgs()
|
||||
@@ -251,18 +275,23 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -275,13 +304,15 @@ public class VentaController:ControllerBase {
|
||||
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{
|
||||
try
|
||||
{
|
||||
var memstream = new MemoryStream();
|
||||
|
||||
var goa = new GetObjectArgs()
|
||||
.WithBucket("alquilafacil")
|
||||
.WithObject(venta.UrlRecibo)
|
||||
.WithCallbackStream(stream => {
|
||||
.WithCallbackStream(stream =>
|
||||
{
|
||||
memstream.Position = 0;
|
||||
stream.CopyTo(memstream);
|
||||
});
|
||||
@@ -293,7 +324,9 @@ public class VentaController:ControllerBase {
|
||||
|
||||
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" });
|
||||
}
|
||||
@@ -301,11 +334,14 @@ public class VentaController:ControllerBase {
|
||||
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
@@ -324,11 +360,14 @@ public class VentaController:ControllerBase {
|
||||
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
@@ -353,16 +392,23 @@ public class VentaController:ControllerBase {
|
||||
.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();
|
||||
}
|
||||
}
|
||||
@@ -374,7 +420,8 @@ public class VentaController:ControllerBase {
|
||||
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)
|
||||
@@ -392,11 +439,14 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -419,16 +469,21 @@ public class VentaController:ControllerBase {
|
||||
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) {
|
||||
&& canonConFechaMasTardia.Fecha.Month >= DateTime.Now.Month)
|
||||
{
|
||||
ret = true;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
@@ -437,11 +492,14 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user