una cosa más hecha

This commit is contained in:
2025-01-25 00:20:47 -03:00
parent 2b481e2ae2
commit f750ecc77e
10 changed files with 249 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
using Entidades.Dto;
namespace AlquilaFacil.Builder;
public class VentasDtoBuilder: Builder<VentasDto> {
public VentasDtoBuilder SetId(long id) {
data.Id = id;
return this;
}
public VentasDtoBuilder SetMonto(decimal monto) {
data.Monto = monto;
return this;
}
public VentasDtoBuilder SetDivisa(string divisa) {
data.Divisa = divisa;
return this;
}
public VentasDtoBuilder SetUbicacion(string ubicacion) {
data.Ubicacion = ubicacion;
return this;
}
public VentasDtoBuilder SetNombreVendedor(string nombre) {
data.NombreVendedor = nombre;
return this;
}
public VentasDtoBuilder SetIdVendedor(long idVendedor) {
data.Id = idVendedor;
return this;
}
public VentasDtoBuilder SetNombreComprador(string nombre) {
data.NombreComprador = nombre;
return this;
}
public VentasDtoBuilder SetIdComprador(long Id) {
data.IdComprador = Id;
return this;
}
public VentasDtoBuilder SetEstado(string estado) {
data.Estado = estado;
return this;
}
}

View File

@@ -47,17 +47,74 @@ public class VentaController:ControllerBase {
}
*/
[HttpGet("/api/venta")]
public IActionResult ObtenerVenta(long idventa) {
public IActionResult ObtenerVenta([FromHeader(Name="Auth")]string Auth, long idventa=0) {
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
if (validacion1 == false){
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
if (validacion1 == false) {
return Unauthorized();
}
}
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();
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??"")
.Build();
return Ok(new { data = v, iscomprador = (ventas.IdComprador==cli.Dni)?true:false});
}
[HttpGet("/api/ventas")]
public IActionResult ObtenerVenta(long idventa) {
public IActionResult ObtenerVenta([FromHeader(Name="Auth")]string Auth) {
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
if (validacion1 == false){
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
if (validacion1 == false) {
return Unauthorized();
}
}
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
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"});
List<VentasDto> lista = new();
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??"")
.Build();
lista.Add(v);
}
return Ok(lista);
}
*/
[HttpGet("/api/opcionventa")]
public IActionResult ObtenerDto([FromHeader(Name="Auth")]string Auth, long idcontrato=0) {
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");