ahi le cambie los checkgrupo por checkpermiso
This commit is contained in:
@@ -6,9 +6,11 @@ using Modelo;
|
|||||||
namespace AlquilaFacil.Controllers;
|
namespace AlquilaFacil.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class PropiedadesController: ControllerBase {
|
public class PropiedadesController : ControllerBase
|
||||||
|
{
|
||||||
[HttpGet("api/propiedades")]
|
[HttpGet("api/propiedades")]
|
||||||
public IActionResult ListarPropiedades([FromHeader(Name = "Auth")] string Auth, int pag = 0) {
|
public IActionResult ListarPropiedades([FromHeader(Name = "Auth")] string Auth, int pag = 0)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
||||||
if (validacion1 == false) validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
if (validacion1 == false) validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
@@ -16,9 +18,12 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
IQueryable<PropiedadesDto> ret;
|
IQueryable<PropiedadesDto> ret;
|
||||||
|
|
||||||
if (pag == 0){
|
if (pag == 0)
|
||||||
|
{
|
||||||
ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
||||||
} else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret = RepositorioPropiedades.Singleton.ListarPropiedadesPorPagina(pag);
|
ret = RepositorioPropiedades.Singleton.ListarPropiedadesPorPagina(pag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,31 +31,35 @@ public class PropiedadesController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("/api/propiedades/Venta")]
|
[HttpGet("/api/propiedades/Venta")]
|
||||||
public IActionResult ObtenerPropiedadesParaVenta([FromHeader(Name = "Auth")] string Auth, int pag = 0) {
|
public IActionResult ObtenerPropiedadesParaVenta([FromHeader(Name = "Auth")] string Auth, int pag = 0)
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
{
|
||||||
if (validacion1 == false) {
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 16);
|
||||||
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pag<=0) return BadRequest(new { message = "no existe una pagina 0"});
|
if (pag <= 0) return BadRequest(new { message = "no existe una pagina 0" });
|
||||||
|
|
||||||
pag-=1;
|
pag -= 1;
|
||||||
|
|
||||||
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesEnVenta(pag);
|
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesEnVenta(pag);
|
||||||
if (props == null) return BadRequest(new { message = "no tengo claro que fallo creo que no existen propiedades en venta"});
|
if (props == null) return BadRequest(new { message = "no tengo claro que fallo creo que no existen propiedades en venta" });
|
||||||
|
|
||||||
List<PropiedadesVentaDto> l = new();
|
List<PropiedadesVentaDto> l = new();
|
||||||
|
|
||||||
foreach (var i in props) {
|
foreach (var i in props)
|
||||||
var p = new PropiedadesVentaDto{
|
{
|
||||||
|
var p = new PropiedadesVentaDto
|
||||||
|
{
|
||||||
Id = i.Id,
|
Id = i.Id,
|
||||||
Ubicacion = i.Ubicacion,
|
Ubicacion = i.Ubicacion,
|
||||||
Canthabitaciones = i.Canthabitaciones,
|
Canthabitaciones = i.Canthabitaciones,
|
||||||
Divisa = i.IddivisaNavigation.Signo,
|
Divisa = i.IddivisaNavigation.Signo,
|
||||||
Letra = i.Letra??"",
|
Letra = i.Letra ?? "",
|
||||||
Monto = i.Monto,
|
Monto = i.Monto,
|
||||||
Piso = i.Piso??0,
|
Piso = i.Piso ?? 0,
|
||||||
Servicios =string.Join(", ", i.IdServicios.Select(s => s.Descripcion)),
|
Servicios = string.Join(", ", i.IdServicios.Select(s => s.Descripcion)),
|
||||||
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
||||||
};
|
};
|
||||||
l.Add(p);
|
l.Add(p);
|
||||||
@@ -58,31 +67,35 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
int cantpag = RepositorioPropiedades.Singleton.ObtenerPaginasDePropiedadesEnVenta();
|
int cantpag = RepositorioPropiedades.Singleton.ObtenerPaginasDePropiedadesEnVenta();
|
||||||
|
|
||||||
return Ok(new { propiedades = l, cantpaginas = cantpag});
|
return Ok(new { propiedades = l, cantpaginas = cantpag });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/propiedades/Venta/Propietario")]
|
[HttpGet("api/propiedades/Venta/Propietario")]
|
||||||
public IActionResult ObtenerPropiedadesVentaDePropietario( [FromHeader(Name = "Auth")] string Auth){
|
public IActionResult ObtenerPropiedadesVentaDePropietario([FromHeader(Name = "Auth")] string Auth)
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
{
|
||||||
if (validacion1 == false) {
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 15);
|
||||||
|
if (validacion1 == false)
|
||||||
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
if (cli == null) return Unauthorized();
|
if (cli == null) return Unauthorized();
|
||||||
|
|
||||||
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesAVentaPorDni(cli.Dni);
|
var props = RepositorioPropiedades.Singleton.ObtenerPropiedadesAVentaPorDni(cli.Dni);
|
||||||
List<PropiedadesDto> ll = new();
|
List<PropiedadesDto> ll = new();
|
||||||
|
|
||||||
foreach (var i in props) {
|
foreach (var i in props)
|
||||||
var a = new PropiedadesDto {
|
{
|
||||||
|
var a = new PropiedadesDto
|
||||||
|
{
|
||||||
id = i.Id,
|
id = i.Id,
|
||||||
Ubicacion = i.Ubicacion,
|
Ubicacion = i.Ubicacion,
|
||||||
canthabitaciones = i.Canthabitaciones,
|
canthabitaciones = i.Canthabitaciones,
|
||||||
Iddivisa = i.Iddivisa,
|
Iddivisa = i.Iddivisa,
|
||||||
letra = i.Letra??"",
|
letra = i.Letra ?? "",
|
||||||
Monto = (int)i.Monto, //mmmm
|
Monto = (int)i.Monto, //mmmm
|
||||||
piso = i.Piso??0,
|
piso = i.Piso ?? 0,
|
||||||
Servicios = string.Join(", ", i.IdServicios.Select(x => x.Descripcion)),
|
Servicios = string.Join(", ", i.IdServicios.Select(x => x.Descripcion)),
|
||||||
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
Tipo = i.IdtipropiedadNavigation.Descripcion,
|
||||||
};
|
};
|
||||||
@@ -92,71 +105,79 @@ public class PropiedadesController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/propiedad")]
|
[HttpGet("api/propiedad")]
|
||||||
public IActionResult ObtenerPropiedadPorId(int Id, [FromHeader(Name = "Auth")] string Auth) {
|
public IActionResult ObtenerPropiedadPorId(int Id, [FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (Id < 0) return BadRequest(new {message ="la id de propiedad no puede ser negativa"});
|
if (Id < 0) return BadRequest(new { message = "la id de propiedad no puede ser negativa" });
|
||||||
|
|
||||||
var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(Id);
|
var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(Id);
|
||||||
if (ret == null) return BadRequest(new {message ="No existe la propiedad"});
|
if (ret == null) return BadRequest(new { message = "No existe la propiedad" });
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/propiedad/cantPagina")]
|
[HttpGet("api/propiedad/cantPagina")]
|
||||||
public IActionResult ObtenerCantidadDePaginas([FromHeader(Name = "Auth")] string Auth, int estado = 0) {
|
public IActionResult ObtenerCantidadDePaginas([FromHeader(Name = "Auth")] string Auth, int estado = 0)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 10);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (estado < 0) return BadRequest(new {message = "No puede tener un numero menor a 0"});
|
if (estado < 0) return BadRequest(new { message = "No puede tener un numero menor a 0" });
|
||||||
int cant;
|
int cant;
|
||||||
|
|
||||||
if(estado == 0){
|
if (estado == 0)
|
||||||
|
{
|
||||||
cant = RepositorioPropiedades.Singleton.CuantasPaginas();
|
cant = RepositorioPropiedades.Singleton.CuantasPaginas();
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cant = RepositorioPropiedades.Singleton.CuantasPaginas(estado);
|
cant = RepositorioPropiedades.Singleton.CuantasPaginas(estado);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(new {message = cant});
|
return Ok(new { message = cant });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/propiedades/Propietario")]
|
[HttpGet("api/propiedades/Propietario")]
|
||||||
public IActionResult ObtenerPropiedadesPorPropietario (
|
public IActionResult ObtenerPropiedadesPorPropietario(
|
||||||
[FromHeader(Name = "Email")] string email,
|
[FromHeader(Name = "Email")] string email,
|
||||||
[FromHeader(Name = "Auth")] string Auth) {
|
[FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
email = email.Trim();
|
email = email.Trim();
|
||||||
if (String.IsNullOrEmpty(email)) return BadRequest(new {message ="falta campo email"});
|
if (String.IsNullOrEmpty(email)) return BadRequest(new { message = "falta campo email" });
|
||||||
|
|
||||||
IQueryable<PropiedadesDto> ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email);
|
IQueryable<PropiedadesDto> ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email);
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/propiedades/Propietario/Bajas")]
|
[HttpGet("api/propiedades/Propietario/Bajas")]
|
||||||
public IActionResult ObtenerPropiedadesPorPropietarioBajas (
|
public IActionResult ObtenerPropiedadesPorPropietarioBajas(
|
||||||
[FromHeader(Name = "Email")] string email,
|
[FromHeader(Name = "Email")] string email,
|
||||||
[FromHeader(Name = "Auth")] string Auth) {
|
[FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 8);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 8);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
email = email.Trim();
|
email = email.Trim();
|
||||||
if (String.IsNullOrEmpty(email)) return BadRequest(new {message ="falta campo email"});
|
if (String.IsNullOrEmpty(email)) return BadRequest(new { message = "falta campo email" });
|
||||||
|
|
||||||
IQueryable<PropiedadesDto> ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesDeBajaPorEmail(email);
|
IQueryable<PropiedadesDto> ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesDeBajaPorEmail(email);
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/propiedad")]
|
[HttpPost("api/propiedad")]
|
||||||
public IActionResult AltaPropiedad([FromBody] AltaPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth) {
|
public IActionResult AltaPropiedad([FromBody] AltaPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 1);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 1);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
@@ -165,9 +186,10 @@ public class PropiedadesController: ControllerBase {
|
|||||||
if (validacion2 != "") return BadRequest(new { message = validacion2 });
|
if (validacion2 != "") return BadRequest(new { message = validacion2 });
|
||||||
|
|
||||||
Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email);
|
Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email);
|
||||||
if (cli == null) return BadRequest(new { message = "El email no corresponde a un propietario"});
|
if (cli == null) return BadRequest(new { message = "El email no corresponde a un propietario" });
|
||||||
|
|
||||||
Propiedade Prop = new Propiedade{
|
Propiedade Prop = new Propiedade
|
||||||
|
{
|
||||||
Canthabitaciones = propiedad.Canthabitaciones,
|
Canthabitaciones = propiedad.Canthabitaciones,
|
||||||
Dnipropietario = cli.Dni,
|
Dnipropietario = cli.Dni,
|
||||||
Idtipropiedad = propiedad.Idtipropiedad,
|
Idtipropiedad = propiedad.Idtipropiedad,
|
||||||
@@ -179,13 +201,14 @@ public class PropiedadesController: ControllerBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
||||||
return (ret)?
|
return (ret) ?
|
||||||
Ok(new { message = "Fue Cargado Correctamente"}) :
|
Ok(new { message = "Fue Cargado Correctamente" }) :
|
||||||
BadRequest(new { message = "Fallo al momento de añadir la propiedad a la base de datos"});
|
BadRequest(new { message = "Fallo al momento de añadir la propiedad a la base de datos" });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("api/propiedad")]
|
[HttpPatch("api/propiedad")]
|
||||||
public IActionResult PatchPropiedad([FromBody] PatchPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth) {
|
public IActionResult PatchPropiedad([FromBody] PatchPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
@@ -195,11 +218,12 @@ public class PropiedadesController: ControllerBase {
|
|||||||
if (validacion2 != "") return BadRequest(new { message = validacion2 });
|
if (validacion2 != "") return BadRequest(new { message = validacion2 });
|
||||||
|
|
||||||
Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email);
|
Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email);
|
||||||
if (cli == null) return BadRequest(new { message = "El email no corresponde a un propietario"});
|
if (cli == null) return BadRequest(new { message = "El email no corresponde a un propietario" });
|
||||||
|
|
||||||
List<Servicio> servs = RepositorioServicios.Singleton.ObtenerServiciosPorDescripcion(propiedad.Servicios);
|
List<Servicio> servs = RepositorioServicios.Singleton.ObtenerServiciosPorDescripcion(propiedad.Servicios);
|
||||||
|
|
||||||
Propiedade Prop = new Propiedade{
|
Propiedade Prop = new Propiedade
|
||||||
|
{
|
||||||
Id = propiedad.id,
|
Id = propiedad.id,
|
||||||
Canthabitaciones = propiedad.Canthabitaciones,
|
Canthabitaciones = propiedad.Canthabitaciones,
|
||||||
Dnipropietario = cli.Dni,
|
Dnipropietario = cli.Dni,
|
||||||
@@ -213,61 +237,64 @@ public class PropiedadesController: ControllerBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop, cli.Dni);
|
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop, cli.Dni);
|
||||||
return (ret)?
|
return (ret) ?
|
||||||
Ok(new {message = "Fue modificado Correctamente"}):
|
Ok(new { message = "Fue modificado Correctamente" }) :
|
||||||
BadRequest(new {message = "Fallo al modificar la base de datos"});
|
BadRequest(new { message = "Fallo al modificar la base de datos" });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("api/propiedad")]
|
[HttpDelete("api/propiedad")]
|
||||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email){
|
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(email)) return BadRequest(new { message = "Fallo al identificarse el usuario"});
|
if (String.IsNullOrEmpty(email)) return BadRequest(new { message = "Fallo al identificarse el usuario" });
|
||||||
if (id <= 0) return BadRequest(new { message = "No es una id valida"});
|
if (id <= 0) return BadRequest(new { message = "No es una id valida" });
|
||||||
|
|
||||||
Cliente? propie = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(email);
|
Cliente? propie = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(email);
|
||||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id, propie);
|
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id, propie);
|
||||||
|
|
||||||
return ret ?
|
return ret ?
|
||||||
Ok(new { message = $"Se Cambio el estado de la propiedad con id {id}"}):
|
Ok(new { message = $"Se Cambio el estado de la propiedad con id {id}" }) :
|
||||||
BadRequest(new {message="Fallo al cambiar el estado de la propiedad"});
|
BadRequest(new { message = "Fallo al cambiar el estado de la propiedad" });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/propiedades/addServicio")]
|
[HttpPut("api/propiedades/addServicio")]
|
||||||
public IActionResult AñadirServicio([FromBody] ServicioAPropiedadDto Servicios, [FromHeader(Name = "Auth")] string Auth) {
|
public IActionResult AñadirServicio([FromBody] ServicioAPropiedadDto Servicios, [FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (Servicios.propiedadid <= 0) return BadRequest(new {message ="No puede tener una id negativa o cero"});
|
if (Servicios.propiedadid <= 0) return BadRequest(new { message = "No puede tener una id negativa o cero" });
|
||||||
if (Servicios.idServicios.Count() < 1) return BadRequest(new {message ="Falta añadir servicios"});
|
if (Servicios.idServicios.Count() < 1) return BadRequest(new { message = "Falta añadir servicios" });
|
||||||
if (Servicios.idServicios.Any(x => x<= 0)) return BadRequest(new {message ="No tienen haber ids negativas o cero de servicio"});
|
if (Servicios.idServicios.Any(x => x <= 0)) return BadRequest(new { message = "No tienen haber ids negativas o cero de servicio" });
|
||||||
|
|
||||||
var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(Servicios.propiedadid);
|
var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(Servicios.propiedadid);
|
||||||
|
|
||||||
bool validacion2 = Servicios.idServicios.Any(x => serv.Contains(x));
|
bool validacion2 = Servicios.idServicios.Any(x => serv.Contains(x));
|
||||||
|
|
||||||
if (validacion2 == true) return BadRequest(new {message ="Hay elementos repetidos"});
|
if (validacion2 == true) return BadRequest(new { message = "Hay elementos repetidos" });
|
||||||
|
|
||||||
bool ret = RepositorioPropiedades.
|
bool ret = RepositorioPropiedades.
|
||||||
Singleton.AñadirServicioAPropiedad(Servicios.propiedadid, Servicios.idServicios);
|
Singleton.AñadirServicioAPropiedad(Servicios.propiedadid, Servicios.idServicios);
|
||||||
|
|
||||||
return ret ?
|
return ret ?
|
||||||
Ok(new {message ="Los Servicios Se Cargaron correctamente a la propiedad"}) : BadRequest(new {message ="No se pudo Cargar los Servicios a la propiedad"});
|
Ok(new { message = "Los Servicios Se Cargaron correctamente a la propiedad" }) : BadRequest(new { message = "No se pudo Cargar los Servicios a la propiedad" });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut("api/propiedades/RmServicio")]
|
[HttpPut("api/propiedades/RmServicio")]
|
||||||
public IActionResult EliminarServicio([FromBody] ServicioAPropiedadDto servicio, [FromHeader(Name = "Auth")] string Auth) {
|
public IActionResult EliminarServicio([FromBody] ServicioAPropiedadDto servicio, [FromHeader(Name = "Auth")] string Auth)
|
||||||
|
{
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (servicio.propiedadid <= 0) return BadRequest(new {message ="No puede tener una id negativa o cero"});
|
if (servicio.propiedadid <= 0) return BadRequest(new { message = "No puede tener una id negativa o cero" });
|
||||||
if (servicio.idServicios.Count() < 1) return BadRequest(new {message ="Falta añadir servicios"});
|
if (servicio.idServicios.Count() < 1) return BadRequest(new { message = "Falta añadir servicios" });
|
||||||
if (servicio.idServicios.Any(x => x<= 0)) return BadRequest(new {message ="No tienen haber ids negativas o cero de servicio"});
|
if (servicio.idServicios.Any(x => x <= 0)) return BadRequest(new { message = "No tienen haber ids negativas o cero de servicio" });
|
||||||
|
|
||||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
|
||||||
@@ -278,11 +305,12 @@ public class PropiedadesController: ControllerBase {
|
|||||||
bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios, cli.Dni);
|
bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios, cli.Dni);
|
||||||
|
|
||||||
return ret ?
|
return ret ?
|
||||||
Ok(new {message ="Se Eliminaron los servicios seleccionados de la propiedad"}) : BadRequest(new {message ="Fallo al eliminarse los servicios de la propiedad"});
|
Ok(new { message = "Se Eliminaron los servicios seleccionados de la propiedad" }) : BadRequest(new { message = "Fallo al eliminarse los servicios de la propiedad" });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ValidarPropiedad(AltaPropiedadDto prop) {
|
private string ValidarPropiedad(AltaPropiedadDto prop)
|
||||||
|
{
|
||||||
if (prop == null) return "Esta mal formado el body de la request";
|
if (prop == null) return "Esta mal formado el body de la request";
|
||||||
|
|
||||||
string ret = "";
|
string ret = "";
|
||||||
@@ -294,21 +322,22 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
||||||
|
|
||||||
if (prop.Monto<=1) ret += "El monto tiene que ser como minimo mayor a 0";
|
if (prop.Monto <= 1) ret += "El monto tiene que ser como minimo mayor a 0";
|
||||||
|
|
||||||
if (prop.Iddivisa<0 || prop.Iddivisa>1) ret += "se tiene que elejir entre AR$ y US$";
|
if (prop.Iddivisa < 0 || prop.Iddivisa > 1) ret += "se tiene que elejir entre AR$ y US$";
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
private string ValidarPropiedad(PatchPropiedadDto prop) {
|
private string ValidarPropiedad(PatchPropiedadDto prop)
|
||||||
|
{
|
||||||
if (prop == null) return "Esta mal formado el body de la request";
|
if (prop == null) return "Esta mal formado el body de la request";
|
||||||
|
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (prop.id <1) ret += "No Cargo el dato de id";
|
if (prop.id < 1) ret += "No Cargo el dato de id";
|
||||||
if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n";
|
if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n";
|
||||||
|
|
||||||
if (prop.id <1 ) ret += "No puede haber una id menor a 1\n";
|
if (prop.id < 1) ret += "No puede haber una id menor a 1\n";
|
||||||
|
|
||||||
if (prop.Canthabitaciones < 0) ret += "No se puede tener una cantidad de habitaciones negativa\n";
|
if (prop.Canthabitaciones < 0) ret += "No se puede tener una cantidad de habitaciones negativa\n";
|
||||||
|
|
||||||
@@ -316,9 +345,9 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
||||||
|
|
||||||
if (prop.Monto<=1) ret += "El monto tiene que ser como minimo mayor a 0";
|
if (prop.Monto <= 1) ret += "El monto tiene que ser como minimo mayor a 0";
|
||||||
|
|
||||||
if (prop.Iddivisa<0 || prop.Iddivisa>1) ret += "se tiene que elejir entre AR$ y US$";
|
if (prop.Iddivisa < 0 || prop.Iddivisa > 1) ret += "se tiene que elejir entre AR$ y US$";
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user