funcionalidad terminada
This commit is contained in:
@@ -14,6 +14,82 @@ namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
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) {
|
||||
return Unauthorized();
|
||||
}
|
||||
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"});
|
||||
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"});
|
||||
|
||||
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{
|
||||
Fechainicio = DateTime.Now,
|
||||
IdVendedor = prop.Dnipropietario,
|
||||
IdComprador = n.Dniremitente,
|
||||
Monto = prop.Monto,
|
||||
Idpropiedad = prop.Id,
|
||||
Iddivisa = prop.Iddivisa,
|
||||
Idestado = 2,
|
||||
|
||||
};
|
||||
|
||||
bool ret = RepositorioVentas.Singleton.IniciarVenta(v, cli.Dni);
|
||||
if (ret){
|
||||
var noti = new NotificacioneBuilder()
|
||||
.SetAccion("Notificacion")
|
||||
.SetMensaje("Debe Realizar el pago para que se registre el traspaso de la propiedad")
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(n.Dniremitente)
|
||||
.SetDniremitente(n.Dnicliente)
|
||||
.SetIdpropiedad(n.Idpropiedad)
|
||||
.SetFecha(DateTime.Now)
|
||||
.Build();
|
||||
ret = RepositorioNotificaciones.Singleton.AltaNotificacion(noti);
|
||||
}
|
||||
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) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
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"});
|
||||
|
||||
RepositorioNotificaciones.Singleton.MarcarComoLeido(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")
|
||||
.SetLeido(false)
|
||||
.SetDnicliente(n.Dniremitente)
|
||||
.SetDniremitente(n.Dnicliente)
|
||||
.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"});
|
||||
}
|
||||
|
||||
[HttpGet("/api/propiedad/EstaALaVenta")]
|
||||
public IActionResult EstaALaVenta([FromHeader(Name="Auth")]string Auth, int idprop=0) {
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
|
||||
Reference in New Issue
Block a user