feat: terminado tema desabilitacion cliente
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
using Entidades.Admin;
|
||||
using Entidades.Dto;
|
||||
using Entidades;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
@@ -26,6 +28,82 @@ public class AdminController: ControllerBase
|
||||
|
||||
IEnumerable<GrupoAdmin> list = RepositorioGrupos.Singleton.ObtenerGruposPorDni(Dni);
|
||||
return Ok(list);
|
||||
}
|
||||
[HttpPatch("api/admin/cliente/addGrupo")]
|
||||
public IActionResult AddGrupoACliente([FromHeader(Name = "Auth")]string Auth, [FromBody]EmailGrupo data){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo);
|
||||
if (ret) return BadRequest(new { message = $"El usuario ya pertenece al grupo {data.grupo}"});
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.AñadirClienteAGrupo(data.email, data.grupo);
|
||||
|
||||
return ret2 ? Ok(new {message = "Se Añadio al Grupo"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
|
||||
[HttpPatch("api/admin/cliente/rmGrupo")]
|
||||
public IActionResult RmGrupoACliente([FromHeader(Name = "Auth")]string Auth, [FromBody]EmailGrupo data){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (data.email == "" || data.grupo == "") return BadRequest(new { message = "Faltan datos en la request" });
|
||||
|
||||
//una ward para que no me bloquee a mi mismo de tener acceso a admin
|
||||
if (data.email == "celu@fedesrv.ddns.net" && data.grupo == "Admin") return BadRequest(new { message = "Si hago esto me estaria bloqueando la cuenta a mi mismo" });
|
||||
|
||||
var ret = RepositorioUsuarios.Singleton.CheckGrupo(data.email, data.grupo);
|
||||
if (!ret) return BadRequest(new { message = $"El usuario no pertenece al grupo {data.grupo}"});
|
||||
|
||||
if (data.grupo == "Propietario") {
|
||||
IQueryable<PropiedadesDto> ret3 = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(data.email);
|
||||
if (ret3.Count() > 0){
|
||||
bool ret4 = RepositorioPropiedades.Singleton.BajaPropiedades(data.email);
|
||||
if (ret4 == false) return BadRequest(new { message = "No se pudo dar de baja las propiedades"});
|
||||
}
|
||||
}
|
||||
if (data.grupo == "Inquilino") {
|
||||
var ret5 = RepositorioContratos.Singleton.ObtenerContratosPorEmailInquilino(data.email);
|
||||
if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"});
|
||||
}
|
||||
|
||||
var ret2 = RepositorioUsuarios.Singleton.EliminarClienteAGrupo(data.email, data.grupo);
|
||||
return ret2 ? Ok(new {message = $"Se elimino del Grupo: {data.grupo}"}): BadRequest(new { message = "Fallo al añadirse al Grupo" });
|
||||
}
|
||||
|
||||
[HttpDelete("api/admin/cliente")]
|
||||
public IActionResult BajaCliente([FromHeader(Name ="Auth")]string Auth, long Dni){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if ( Dni <=0) return BadRequest(new {message = "No puede tener un Dni menor o igual a 0"});
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorDni(Dni);
|
||||
|
||||
if (cli == null) return BadRequest(new {message = "No existe un cliente con ese numero de dni"});
|
||||
|
||||
bool esPropietario = RepositorioUsuarios.Singleton.CheckGrupo(cli.Email, "Propietario");
|
||||
bool esInquilino = RepositorioUsuarios.Singleton.CheckGrupo(cli.Email, "Inquilino");
|
||||
|
||||
if (esPropietario) {
|
||||
IQueryable<PropiedadesDto> ret3 = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(cli.Email);
|
||||
if (ret3.Count() > 0){
|
||||
bool ret4 = RepositorioPropiedades.Singleton.BajaPropiedades(cli.Email);
|
||||
if (ret4 == false) return BadRequest(new { message = "No se pudo dar de baja las propiedades"});
|
||||
}
|
||||
}
|
||||
|
||||
if (esInquilino) {
|
||||
var ret5 = RepositorioContratos.Singleton.ObtenerContratosPorEmailInquilino(cli.Email);
|
||||
if ( ret5 == null || ret5.Where(x=>x.Habilitado == 0).Count() > 0) return BadRequest(new { message = "Aun tenes alquileres pendientes o fallo al intentar obtener la lista de alquileres, no se puede dar de baja"});
|
||||
}
|
||||
// lo da de baja si no tiene el grupo propietario y no tiene alquileres pendientes
|
||||
var ret = RepositorioUsuarios.Singleton.BajaCliente(Dni);
|
||||
return Ok(ret);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public class PropiedadesController: ControllerBase {
|
||||
public IActionResult ListarPropiedades([FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 12);
|
||||
if (validacion1 == false) validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
||||
@@ -81,6 +82,7 @@ public class PropiedadesController: ControllerBase {
|
||||
Ubicacion = propiedad.Ubicacion,
|
||||
Letra = propiedad.Letra ?? null,
|
||||
Piso = propiedad.Piso ?? null,
|
||||
Monto = propiedad.Monto,
|
||||
};
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
||||
@@ -113,6 +115,7 @@ public class PropiedadesController: ControllerBase {
|
||||
Letra = propiedad.Letra ?? null,
|
||||
Piso = propiedad.Piso ?? null,
|
||||
IdServicios = servs,
|
||||
Monto = propiedad.Monto
|
||||
};
|
||||
|
||||
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop);
|
||||
@@ -193,8 +196,9 @@ public class PropiedadesController: ControllerBase {
|
||||
|
||||
if (prop.Idtipropiedad <= 0) ret += "No tiene un tipo de propiedad asociada\n";
|
||||
|
||||
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad";
|
||||
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";
|
||||
return ret;
|
||||
|
||||
}
|
||||
@@ -211,8 +215,9 @@ public class PropiedadesController: ControllerBase {
|
||||
|
||||
if (prop.tipo <= 0) ret += "No tiene un tipo de propiedad asociada\n";
|
||||
|
||||
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad";
|
||||
|
||||
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";
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user