AdminUsuarios #33
109
Aspnet/Controllers/AdminController.cs
Normal file
109
Aspnet/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Modelo;
|
||||||
|
using Entidades.Admin;
|
||||||
|
using Entidades.Dto;
|
||||||
|
using Entidades;
|
||||||
|
namespace AlquilaFacil.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
public class AdminController: ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("api/admin/clientes")]
|
||||||
|
public IActionResult GetClientes([FromHeader(Name ="Auth")]string Auth){
|
||||||
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 9);
|
||||||
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
|
IEnumerable<UsuarioAdmin>list = RepositorioUsuarios.Singleton.GetClientes();
|
||||||
|
return Ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("api/admin/clientes/grupo")]
|
||||||
|
public IActionResult GetGruposByCliente([FromHeader(Name ="Auth")]string Auth, [FromQuery]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 con numero negativo o cero"});
|
||||||
|
|
||||||
|
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) {
|
public IActionResult ListarPropiedades([FromHeader(Name = "Auth")] string Auth) {
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 12);
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 12);
|
||||||
|
if (validacion1 == false) validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
var ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
var ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
||||||
@@ -81,6 +82,7 @@ public class PropiedadesController: ControllerBase {
|
|||||||
Ubicacion = propiedad.Ubicacion,
|
Ubicacion = propiedad.Ubicacion,
|
||||||
Letra = propiedad.Letra ?? null,
|
Letra = propiedad.Letra ?? null,
|
||||||
Piso = propiedad.Piso ?? null,
|
Piso = propiedad.Piso ?? null,
|
||||||
|
Monto = propiedad.Monto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
||||||
@@ -113,6 +115,7 @@ public class PropiedadesController: ControllerBase {
|
|||||||
Letra = propiedad.Letra ?? null,
|
Letra = propiedad.Letra ?? null,
|
||||||
Piso = propiedad.Piso ?? null,
|
Piso = propiedad.Piso ?? null,
|
||||||
IdServicios = servs,
|
IdServicios = servs,
|
||||||
|
Monto = propiedad.Monto
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ret = RepositorioPropiedades.Singleton.PatchPropiedad(Prop);
|
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 (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;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -211,8 +215,9 @@ public class PropiedadesController: ControllerBase {
|
|||||||
|
|
||||||
if (prop.tipo <= 0) ret += "No tiene un tipo de propiedad asociada\n";
|
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;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
Entidades/Admin/EmailGrupo.cs
Normal file
2
Entidades/Admin/EmailGrupo.cs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
namespace Entidades.Admin;
|
||||||
|
public record EmailGrupo(string email, string grupo);
|
||||||
7
Entidades/Admin/GrupoAdmin.cs
Normal file
7
Entidades/Admin/GrupoAdmin.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Entidades.Admin;
|
||||||
|
|
||||||
|
public class GrupoAdmin {
|
||||||
|
public int Id {get; set;} = 0;
|
||||||
|
public String Descripcion {get; set;} = "";
|
||||||
|
public List<Entidades.Admin.PermisoAdmin> Permisos {get; set;} = new();
|
||||||
|
}
|
||||||
6
Entidades/Admin/PermisosAdmin.cs
Normal file
6
Entidades/Admin/PermisosAdmin.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Entidades.Admin;
|
||||||
|
|
||||||
|
public class PermisoAdmin {
|
||||||
|
public int Id {get; set;}
|
||||||
|
public String Descripcion {get; set;} = "";
|
||||||
|
}
|
||||||
8
Entidades/Admin/UsuarioAdmin.cs
Normal file
8
Entidades/Admin/UsuarioAdmin.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Entidades.Admin;
|
||||||
|
|
||||||
|
public record UsuarioAdmin {
|
||||||
|
public long Dni { get; set; } = 0;
|
||||||
|
public string Nombre { get; set; } = "";
|
||||||
|
public string Email { get; set; } = "";
|
||||||
|
public ulong Habilitado { get; set; }
|
||||||
|
}
|
||||||
@@ -436,6 +436,9 @@ public partial class AlquilaFacilContext : DbContext
|
|||||||
.HasMaxLength(1)
|
.HasMaxLength(1)
|
||||||
.IsFixedLength()
|
.IsFixedLength()
|
||||||
.HasColumnName("letra");
|
.HasColumnName("letra");
|
||||||
|
entity.Property(e => e.Monto)
|
||||||
|
.HasPrecision(10)
|
||||||
|
.HasColumnName("monto");
|
||||||
entity.Property(e => e.Piso)
|
entity.Property(e => e.Piso)
|
||||||
.HasColumnType("int(11)")
|
.HasColumnType("int(11)")
|
||||||
.HasColumnName("piso");
|
.HasColumnName("piso");
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ public class AltaPropiedadDto {
|
|||||||
public string? Letra { get; set; } = null;
|
public string? Letra { get; set; } = null;
|
||||||
public string Email { get; set; } = string.Empty;
|
public string Email { get; set; } = string.Empty;
|
||||||
public int Idtipropiedad { get; set; }
|
public int Idtipropiedad { get; set; }
|
||||||
|
public int Monto { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Entidades.Dto;
|
namespace Entidades.Dto;
|
||||||
|
//WIP
|
||||||
public class CrearContratoDto {
|
public class CrearContratoDto {
|
||||||
public int Meses {get; set;}
|
public int Meses {get; set;}
|
||||||
public int Idpropiedad {get; set;}
|
public int Idpropiedad {get; set;}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Entidades.Dto;
|
namespace Entidades.Dto;
|
||||||
|
|
||||||
public record PatchPropiedadDto(int id, string Ubicacion, int Canthabitaciones, int? Piso, string? Letra, string Email, int tipo, List<string> Servicios);
|
public record PatchPropiedadDto(int id, string Ubicacion, int Canthabitaciones, int? Piso, string? Letra, string Email, int tipo, List<string> Servicios, int Monto);
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ public class PropiedadesDto {
|
|||||||
public string letra { get; set; } = "";
|
public string letra { get; set; } = "";
|
||||||
public string Tipo { get; set; } = "";
|
public string Tipo { get; set; } = "";
|
||||||
public string? Servicios {get;set;} = "";
|
public string? Servicios {get;set;} = "";
|
||||||
|
public int Monto { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public partial class Propiedade
|
|||||||
|
|
||||||
public int? Idestado { get; set; }
|
public int? Idestado { get; set; }
|
||||||
|
|
||||||
|
public decimal Monto { get; set; }
|
||||||
|
|
||||||
public virtual ICollection<Contrato> Contratos { get; set; } = new List<Contrato>();
|
public virtual ICollection<Contrato> Contratos { get; set; } = new List<Contrato>();
|
||||||
|
|
||||||
public virtual Cliente? DnipropietarioNavigation { get; set; }
|
public virtual Cliente? DnipropietarioNavigation { get; set; }
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
import FrontPropietario from "./paginas/grupos/PropietarioG.svelte";
|
import FrontPropietario from "./paginas/grupos/PropietarioG.svelte";
|
||||||
import PublicarPropiedad from "./paginas/PublicarPropiedad.svelte";
|
import PublicarPropiedad from "./paginas/PublicarPropiedad.svelte";
|
||||||
import BusquedaPropiedades from "./paginas/BusquedaPropiedades.svelte";
|
import BusquedaPropiedades from "./paginas/BusquedaPropiedades.svelte";
|
||||||
|
import ControlUsuarios from "./paginas/ControlUsuarios.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Router>
|
<Router>
|
||||||
@@ -61,6 +62,12 @@
|
|||||||
<ProteRoute componente={MisPropiedadesDeBaja}/>
|
<ProteRoute componente={MisPropiedadesDeBaja}/>
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
<!-- Pantalla Control Usuarios -->
|
||||||
|
<Route path="/accion/9">
|
||||||
|
<ProteRoute componente={ControlUsuarios}/>
|
||||||
|
</Route>
|
||||||
|
|
||||||
|
|
||||||
<!--Paginas info Grupo-->
|
<!--Paginas info Grupo-->
|
||||||
<Route path="/grupo/Inquilino">
|
<Route path="/grupo/Inquilino">
|
||||||
<ProteRoute componente={FrontInquilino}/>
|
<ProteRoute componente={FrontInquilino}/>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let prop = $props();
|
let {text} = $props();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col"><hr></div>
|
<div class="col"><hr></div>
|
||||||
<div class="col-auto"><h5>{prop.text}</h5></div>
|
<div class="col-auto"><h5>{text}</h5></div>
|
||||||
<div class="col"><hr></div>
|
<div class="col"><hr></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<strong>Piso:</strong> {prop.piso || "N/A"}<br>
|
<strong>Piso:</strong> {prop.piso || "N/A"}<br>
|
||||||
<strong>Letra:</strong> {prop.letra || "N/A"}<br>
|
<strong>Letra:</strong> {prop.letra || "N/A"}<br>
|
||||||
<strong>Servicios:</strong> {prop.servicios || "Sin servicios especificados"}
|
<strong>Servicios:</strong> {prop.servicios || "Sin servicios especificados"}
|
||||||
|
<strong>Monto:</strong> ${prop.monto}<br>
|
||||||
</p>
|
</p>
|
||||||
<button class="btn btn-primary">Consultar</button>
|
<button class="btn btn-primary">Consultar</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import ModalEstatico from "./ModalEstatico.svelte";
|
import ModalEstatico from "./ModalEstatico.svelte";
|
||||||
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
import ModificarPropiedadForm from "./modificarPropiedadForm.svelte";
|
||||||
|
|
||||||
let { id, ubicacion, tipo, letra, piso,canthabitaciones, servicios, btnbaja = "Baja" } = $props();
|
let { id, ubicacion, tipo, letra, piso,canthabitaciones, servicios, btnbaja = "Baja", monto } = $props();
|
||||||
|
|
||||||
import { urlG } from "../stores/urlStore";
|
import { urlG } from "../stores/urlStore";
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@
|
|||||||
<td>{piso}</td>
|
<td>{piso}</td>
|
||||||
<td>{tipo}</td>
|
<td>{tipo}</td>
|
||||||
<td>{servicios}</td>
|
<td>{servicios}</td>
|
||||||
|
<td>{monto}</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<button class="btn btn-outline-secondary" onclick={()=> setmod()}>Modificar</button>
|
<button class="btn btn-outline-secondary" onclick={()=> setmod()}>Modificar</button>
|
||||||
<button class="btn btn-outline-secondary" >Ver Más</button>
|
|
||||||
<button class="btn btn-outline-danger" onclick={() => BajaPropiedad()}>{btnbaja}</button>
|
<button class="btn btn-outline-danger" onclick={() => BajaPropiedad()}>{btnbaja}</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
{#if modificar}
|
{#if modificar}
|
||||||
<tr transition:fade={{duration:100}}>
|
<tr transition:fade={{duration:100}}>
|
||||||
<td colspan="8">
|
<td colspan="8">
|
||||||
<ModificarPropiedadForm {id} {ubicacion} {canthabitaciones} {letra} {piso} {tipo} {servicios}/>
|
<ModificarPropiedadForm {id} {ubicacion} {canthabitaciones} {letra} {piso} {tipo} {servicios} {monto}/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { urlG } from "../stores/urlStore";
|
import { urlG } from "../stores/urlStore";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
let { canthabitaciones, id, letra, piso, tipo, ubicacion, servicios } = $props();
|
let { canthabitaciones, id, letra, piso, tipo, ubicacion, servicios, monto } = $props();
|
||||||
let serviciosSeleccionados: string[] = $state([]);
|
let serviciosSeleccionados: string[] = $state([]);
|
||||||
const serviciosDisponibles = ["Gas", "Internet", "Telefono", "Luz"];
|
const serviciosDisponibles = ["Gas", "Internet", "Telefono", "Luz"];
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
ubicacion,
|
ubicacion,
|
||||||
email,
|
email,
|
||||||
servicios: serviciosSeleccionados,
|
servicios: serviciosSeleccionados,
|
||||||
|
monto
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -116,6 +117,17 @@
|
|||||||
/>
|
/>
|
||||||
<label for="piso">Piso</label>
|
<label for="piso">Piso</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="monto"
|
||||||
|
class="form-control"
|
||||||
|
bind:value={monto}
|
||||||
|
min="1"
|
||||||
|
placeholder={monto}
|
||||||
|
/>
|
||||||
|
<label for="monto">Monto</label>
|
||||||
|
</div>
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
|||||||
241
Front/src/paginas/ControlUsuarios.svelte
Normal file
241
Front/src/paginas/ControlUsuarios.svelte
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||||
|
import type { Cliente, Grupo } from "../types";
|
||||||
|
import {urlG} from "../stores/urlStore";
|
||||||
|
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||||
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
|
import { fade, fly } from "svelte/transition";
|
||||||
|
|
||||||
|
let Clientes: Cliente[] = $state([]);
|
||||||
|
let Grupos:any[] = $state([]);
|
||||||
|
let modaldata = $state();
|
||||||
|
let token = sessionStorage.getItem("token");
|
||||||
|
let showAddmenu: boolean = $state(false);
|
||||||
|
|
||||||
|
let grupo:string = $state("");
|
||||||
|
let SelCliente: Cliente = $state();
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
try{
|
||||||
|
const response = await fetch($urlG+"/api/admin/clientes", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (response.ok) {
|
||||||
|
let data: Cliente[] = await response.json();
|
||||||
|
Clientes = data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
modaldata = "fallo al asignar la lista de clientes";
|
||||||
|
} catch {
|
||||||
|
modaldata = "fallo al intentar obtener la lista de clientes";
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
async function cargaGrupos(cli: Cliente){
|
||||||
|
try {
|
||||||
|
const response = await fetch($urlG+"/api/admin/clientes/grupo?Dni="+cli.dni, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (response.ok){
|
||||||
|
let data = await response.json();
|
||||||
|
Grupos = data;
|
||||||
|
showAddmenu = true;
|
||||||
|
SelCliente = cli;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
modaldata = await response.json();
|
||||||
|
} catch {
|
||||||
|
modaldata = "no se pudo obtener la lista de grupos";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bajaCliente(event:Event, cli:Cliente) {
|
||||||
|
//WIP añadir una flag para que muestre que no se pudo dar se alta/baja
|
||||||
|
event.stopPropagation();
|
||||||
|
try {
|
||||||
|
const response = await fetch($urlG+"/api/admin/cliente?Dni="+cli.dni, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(response.ok){
|
||||||
|
let data = await response.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
cli.habilitado = !cli.habilitado;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
modaldata = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
async function añadirGrupo(e:Event, cli: Cliente, grupo:string){
|
||||||
|
e.preventDefault();
|
||||||
|
if (cli.dni == 0 || cli.email == "" || grupo == ""){
|
||||||
|
modaldata = "No se selecciono un cliente o Grupo";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const email = cli.email;
|
||||||
|
try {
|
||||||
|
const response = await fetch($urlG+"/api/admin/cliente/addGrupo", {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
'Content-Type' : 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({email, grupo})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok){
|
||||||
|
let data = await response.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
cargaGrupos(cli);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let data = await response.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
} catch {
|
||||||
|
modaldata = "Falla la conexion al servidor";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function BajaGrupo(e:Event, cli: Cliente, grupo:string){
|
||||||
|
e.preventDefault();
|
||||||
|
if (cli.dni == 0 || cli.email == "" || grupo == ""){
|
||||||
|
modaldata = "No se selecciono un cliente o Grupo";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const email = cli.email;
|
||||||
|
if (grupo === "Propietario"){
|
||||||
|
if (confirm("Sos propietario si te desactivas de ese rol tus propiedades se van a dar de baja, Estas seguro?") == false) return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch($urlG+"/api/admin/cliente/rmGrupo", {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Auth": String(token),
|
||||||
|
'Content-Type' : 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({email, grupo})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok){
|
||||||
|
let data = await response.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
cargaGrupos(cli);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let data = await response.json();
|
||||||
|
modaldata = data.message;
|
||||||
|
} catch {
|
||||||
|
modaldata = "Falla la conexion al servidor";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<NavBarAutocompletable/>
|
||||||
|
|
||||||
|
{#if modaldata}
|
||||||
|
<ModalEstatico payload={modaldata} close={()=> !!(modaldata = "")}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="content-fluid align-items-start">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col" style="padding-right: 2px;">
|
||||||
|
<BarraHorizontalConTexto text="Clientes"/>
|
||||||
|
|
||||||
|
<div style="height:70vh; overflow-y: auto; max-width: 100%">
|
||||||
|
<table class="table table-responsive table-sm table-striped table-hover table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Dni</th>
|
||||||
|
<th>Nombre/Apellido</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each Clientes as cli}
|
||||||
|
<tr onclick={() => cargaGrupos(cli)} in:fade>
|
||||||
|
<td>{cli.dni}</td>
|
||||||
|
<td>{cli.nombre}</td>
|
||||||
|
<td>{cli.email}</td>
|
||||||
|
<td>
|
||||||
|
{#if cli.habilitado}
|
||||||
|
<button class="btn btn-outline-warning" onclick={(e) => bajaCliente(e, cli)}>
|
||||||
|
Baja
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button class="btn btn-outline-success" onclick={(e) => bajaCliente(e, cli)}>
|
||||||
|
Alta
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col"style="padding-left: 2px;">
|
||||||
|
<BarraHorizontalConTexto text="Grupos del Cliente Seleccionado"/>
|
||||||
|
<table class="table table-striped table-responsive table-sm table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Descripcion</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#if Grupos.length>0}
|
||||||
|
|
||||||
|
{#each Grupos as g}
|
||||||
|
<tr in:fade>
|
||||||
|
<td>{g.id}</td>
|
||||||
|
<td>{g.descripcion}</td>
|
||||||
|
<td><button class="btn btn-outline-danger" onclick={(e)=>BajaGrupo(e, SelCliente, g.descripcion)}>Baja</button></td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
{:else if SelCliente != null}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">Este Cliente no tiene Grupos</td>
|
||||||
|
</tr>
|
||||||
|
{:else}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">Seleccione un cliente para ver sus grupos</td>
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{#if showAddmenu}
|
||||||
|
<div in:fade>
|
||||||
|
<BarraHorizontalConTexto text="Añadir Grupos al Usuario"/>
|
||||||
|
<form class="card card-body" onsubmit={(e) => añadirGrupo(e,SelCliente, grupo)}>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="userRole" class="form-label">Seleccionar Grupo</label>
|
||||||
|
<select id="userRole" class="form-select" bind:value={grupo}>
|
||||||
|
<option value="Propietario">Propietario</option>
|
||||||
|
<option value="Inquilino">Inquilino</option>
|
||||||
|
<option value="Admin">Admin</option>
|
||||||
|
<option value="Informes">Informes</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary" type="submit">Añadir</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||||
import type { PropiedadDto } from "../types";
|
import type { PropiedadDto } from "../types";
|
||||||
import { urlG } from "../stores/urlStore";
|
import { urlG } from "../stores/urlStore";
|
||||||
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
|
|
||||||
let propiedades = writable<PropiedadDto[]>([]);
|
let propiedades = writable<PropiedadDto[]>([]);
|
||||||
let email = localStorage.getItem("email");
|
let email = localStorage.getItem("email");
|
||||||
@@ -39,11 +40,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<NavBarAutocompletable/>
|
<NavBarAutocompletable/>
|
||||||
<h1 class="text-center">
|
<BarraHorizontalConTexto text="Propiedades dadas de Alta"/>
|
||||||
Propiedades de Alta
|
<div class="container table-responsive">
|
||||||
</h1>
|
<table class="container-fluid table-responsive table table-striped table-bordered">
|
||||||
<div class="container table-responsive border border-success">
|
|
||||||
<table class="table-responsive table table-striped">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
@@ -53,12 +52,13 @@
|
|||||||
<th>Piso</th>
|
<th>Piso</th>
|
||||||
<th>Tipo</th>
|
<th>Tipo</th>
|
||||||
<th>Servicios</th>
|
<th>Servicios</th>
|
||||||
|
<th>Monto</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each $propiedades as propiedad}
|
{#each $propiedades as propiedad}
|
||||||
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones} servicios={propiedad.servicios} />
|
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones} servicios={propiedad.servicios} monto={propiedad.monto} />
|
||||||
|
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||||
import type { PropiedadDto } from "../types";
|
import type { PropiedadDto } from "../types";
|
||||||
import { urlG } from "../stores/urlStore";
|
import { urlG } from "../stores/urlStore";
|
||||||
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
|
|
||||||
let propiedades = writable<PropiedadDto[]>([]);
|
let propiedades = writable<PropiedadDto[]>([]);
|
||||||
let email = localStorage.getItem("email");
|
let email = localStorage.getItem("email");
|
||||||
@@ -39,11 +40,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<NavBarAutocompletable/>
|
<NavBarAutocompletable/>
|
||||||
<h1 class="text-center">
|
<BarraHorizontalConTexto text="Propiedades dadas de Baja"/>
|
||||||
Propiedades de Baja
|
|
||||||
</h1>
|
<div class="container table-responsive">
|
||||||
<div class="container table-responsive border border-success">
|
<table class="table-responsive table table-striped table-bordered">
|
||||||
<table class="table-responsive table table-striped">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
@@ -53,12 +53,13 @@
|
|||||||
<th>Piso</th>
|
<th>Piso</th>
|
||||||
<th>Tipo</th>
|
<th>Tipo</th>
|
||||||
<th>Servicios</th>
|
<th>Servicios</th>
|
||||||
|
<th>Monto</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each $propiedades as propiedad}
|
{#each $propiedades as propiedad}
|
||||||
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones} servicios={propiedad.servicios} btnbaja={"Alta"}/>
|
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo} canthabitaciones={propiedad.canthabitaciones} servicios={propiedad.servicios} btnbaja={"Alta"} monto={propiedad.monto}/>
|
||||||
|
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
letra: "",
|
letra: "",
|
||||||
email: localStorage.getItem("email") || "",
|
email: localStorage.getItem("email") || "",
|
||||||
idtipropiedad: 1,
|
idtipropiedad: 1,
|
||||||
|
monto: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let token = sessionStorage.getItem("token");
|
let token = sessionStorage.getItem("token");
|
||||||
@@ -93,6 +94,17 @@
|
|||||||
/>
|
/>
|
||||||
<label for="piso">Piso</label>
|
<label for="piso">Piso</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="monto"
|
||||||
|
class="form-control"
|
||||||
|
bind:value={propiedad.monto}
|
||||||
|
min="1"
|
||||||
|
placeholder="1"
|
||||||
|
/>
|
||||||
|
<label for="monto">Monto</label>
|
||||||
|
</div>
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
|||||||
11
Front/src/types.d.ts
vendored
11
Front/src/types.d.ts
vendored
@@ -5,13 +5,21 @@ export type PropiedadDto = {
|
|||||||
piso: string | null,
|
piso: string | null,
|
||||||
letra: string | null,
|
letra: string | null,
|
||||||
canthabitaciones: number,
|
canthabitaciones: number,
|
||||||
servicios: string
|
servicios: string,
|
||||||
|
monto: number
|
||||||
}
|
}
|
||||||
export type Permiso = {
|
export type Permiso = {
|
||||||
id: number;
|
id: number;
|
||||||
descripcion: string;
|
descripcion: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Cliente = {
|
||||||
|
dni: number,
|
||||||
|
nombre: string,
|
||||||
|
email: string,
|
||||||
|
habilitado: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export type Grupo = {
|
export type Grupo = {
|
||||||
id: number;
|
id: number;
|
||||||
nombre: string;
|
nombre: string;
|
||||||
@@ -25,4 +33,5 @@ export type Propiedad = {
|
|||||||
letra: string,
|
letra: string,
|
||||||
email: string,
|
email: string,
|
||||||
idtipropiedad: number,
|
idtipropiedad: number,
|
||||||
|
monto: number
|
||||||
};
|
};
|
||||||
|
|||||||
15
Modelo/RepositorioContratos.cs
Normal file
15
Modelo/RepositorioContratos.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Entidades;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Modelo;
|
||||||
|
public class RepositorioContratos: RepositorioBase<RepositorioContratos> {
|
||||||
|
public IQueryable<Contrato>? ObtenerContratosPorEmailInquilino(string email){
|
||||||
|
var con = Context;
|
||||||
|
try{
|
||||||
|
var listcont = con.Contratos.Where(x=>x.DniinquilinoNavigation.Email == email);
|
||||||
|
return listcont;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#if DEBUG
|
|
||||||
|
|
||||||
using Entidades;
|
using Entidades;
|
||||||
|
using Entidades.Admin;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Modelo;
|
namespace Modelo;
|
||||||
@@ -23,6 +22,14 @@ public class RepositorioGrupos: RepositorioBase<RepositorioGrupos> {
|
|||||||
var con = Context;
|
var con = Context;
|
||||||
return con.Grupos.Where(x=>x.Nombre == grupo).SelectMany(x => x.Idpermisos);
|
return con.Grupos.Where(x=>x.Nombre == grupo).SelectMany(x => x.Idpermisos);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
public IQueryable<GrupoAdmin> ObtenerGruposPorDni(long Dni) {
|
||||||
|
var con = Context;
|
||||||
|
var grupos = con.Clientes.Where(x=>x.Dni == Dni).SelectMany(x=>x.Idgrupos)
|
||||||
|
.Select(x=> new GrupoAdmin{
|
||||||
|
Id = x.Id,
|
||||||
|
Descripcion = x.Nombre,
|
||||||
|
});
|
||||||
|
return grupos;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
|||||||
public IQueryable<PropiedadesDto> ListarPropiedades(){
|
public IQueryable<PropiedadesDto> ListarPropiedades(){
|
||||||
FormattableString sqlq = $"""
|
FormattableString sqlq = $"""
|
||||||
SELECT DISTINCT p.id, p.ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion AS Tipo,
|
SELECT DISTINCT p.id, p.ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion AS Tipo,
|
||||||
GROUP_CONCAT(DISTINCT s.descripcion SEPARATOR ', ') AS Servicios
|
GROUP_CONCAT(DISTINCT s.descripcion SEPARATOR ', ') AS Servicios, p.monto as Monto
|
||||||
FROM Propiedades p
|
FROM Propiedades p
|
||||||
JOIN EstadoPropiedad ep ON p.idestado = 1
|
JOIN EstadoPropiedad ep ON p.idestado = 1
|
||||||
JOIN TipoPropiedad tp ON p.idtipropiedad = tp.id
|
JOIN TipoPropiedad tp ON p.idtipropiedad = tp.id
|
||||||
@@ -41,35 +41,36 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
|||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AñadirPropiedad(Propiedade? prop) {
|
public bool AñadirPropiedad(Propiedade? prop) {
|
||||||
if (prop == null) return false;
|
if (prop == null) return false;
|
||||||
|
|
||||||
var con = Context;
|
var con = Context;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(prop.Letra)) prop.Letra = "_";
|
if (string.IsNullOrEmpty(prop.Letra)) prop.Letra = "_";
|
||||||
|
|
||||||
var filasInsertadasParam = new MySqlParameter("@p_filas_insertadas", SqlDbType.Int)
|
var filasInsertadasParam = new MySqlParameter("@p_filas_insertadas", SqlDbType.Int)
|
||||||
{
|
{
|
||||||
Direction = ParameterDirection.Output
|
Direction = ParameterDirection.Output
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ejecutar el procedimiento almacenado
|
// Ejecutar el procedimiento almacenado
|
||||||
var row = con.Database.ExecuteSqlRaw(
|
var row = con.Database.ExecuteSqlRaw(
|
||||||
$"""
|
$"""
|
||||||
CALL InsertarPropiedad(@p_ubicacion, @p_cant_habitaciones, @p_piso, @p_letra,
|
CALL InsertarPropiedad(@p_ubicacion, @p_cant_habitaciones, @p_piso, @p_letra,
|
||||||
@p_dni_propietario, @p_id_tipo_propiedad, @p_filas_insertadas)
|
@p_dni_propietario, @p_id_tipo_propiedad, @p_monto, @p_filas_insertadas)
|
||||||
""",
|
""",
|
||||||
new MySqlParameter("@p_ubicacion", prop.Ubicacion),
|
new MySqlParameter("@p_ubicacion", prop.Ubicacion),
|
||||||
new MySqlParameter("@p_cant_habitaciones", prop.Canthabitaciones),
|
new MySqlParameter("@p_cant_habitaciones", prop.Canthabitaciones),
|
||||||
new MySqlParameter("@p_piso", prop.Piso),
|
new MySqlParameter("@p_piso", prop.Piso),
|
||||||
new MySqlParameter("@p_letra", prop.Letra),
|
new MySqlParameter("@p_letra", prop.Letra),
|
||||||
new MySqlParameter("@p_dni_propietario", prop.Dnipropietario),
|
new MySqlParameter("@p_dni_propietario", prop.Dnipropietario),
|
||||||
new MySqlParameter("@p_id_tipo_propiedad", prop.Idtipropiedad),
|
new MySqlParameter("@p_id_tipo_propiedad", prop.Idtipropiedad),
|
||||||
filasInsertadasParam
|
new MySqlParameter("@p_monto",prop.Monto),
|
||||||
);
|
filasInsertadasParam
|
||||||
|
);
|
||||||
|
|
||||||
return (int)filasInsertadasParam.Value == 1? true: false;
|
return (int)filasInsertadasParam.Value == 1? true: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool PatchPropiedad(Propiedade prop) {
|
public bool PatchPropiedad(Propiedade prop) {
|
||||||
var con = Context;
|
var con = Context;
|
||||||
@@ -82,6 +83,7 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
|||||||
propi.Ubicacion = prop.Ubicacion;
|
propi.Ubicacion = prop.Ubicacion;
|
||||||
propi.Piso = prop.Piso;
|
propi.Piso = prop.Piso;
|
||||||
propi.Letra = prop.Letra;
|
propi.Letra = prop.Letra;
|
||||||
|
propi.Monto = prop.Monto;
|
||||||
|
|
||||||
propi.IdServicios.Clear();
|
propi.IdServicios.Clear();
|
||||||
foreach(Servicio ser in prop.IdServicios) {
|
foreach(Servicio ser in prop.IdServicios) {
|
||||||
@@ -95,7 +97,7 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
|||||||
|
|
||||||
public IQueryable<PropiedadesDto> ObtenerPropiedadesPorEmail(string email) {
|
public IQueryable<PropiedadesDto> ObtenerPropiedadesPorEmail(string email) {
|
||||||
FormattableString sqlq = $"""
|
FormattableString sqlq = $"""
|
||||||
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo, GROUP_CONCAT(IFNULL(s.descripcion, '') SEPARATOR ', ') AS Servicios
|
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo, GROUP_CONCAT(IFNULL(s.descripcion, '') SEPARATOR ', ') AS Servicios, p.monto as Monto
|
||||||
FROM Propiedades p
|
FROM Propiedades p
|
||||||
JOIN Clientes c ON c.dni = p.dnipropietario
|
JOIN Clientes c ON c.dni = p.dnipropietario
|
||||||
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
||||||
@@ -111,7 +113,7 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
|||||||
|
|
||||||
public IQueryable<PropiedadesDto> ObtenerPropiedadesDeBajaPorEmail(string email) {
|
public IQueryable<PropiedadesDto> ObtenerPropiedadesDeBajaPorEmail(string email) {
|
||||||
FormattableString sqlq = $"""
|
FormattableString sqlq = $"""
|
||||||
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo, GROUP_CONCAT(IFNULL(s.descripcion, '') SEPARATOR ', ') AS Servicios
|
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo, GROUP_CONCAT(IFNULL(s.descripcion, '') SEPARATOR ', ') AS Servicios, p.monto as Monto
|
||||||
FROM Propiedades p
|
FROM Propiedades p
|
||||||
JOIN Clientes c ON c.dni = p.dnipropietario
|
JOIN Clientes c ON c.dni = p.dnipropietario
|
||||||
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
||||||
@@ -326,4 +328,17 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
|||||||
var ret = Context.Database.SqlQuery<PropiedadesDto>(sqlq);
|
var ret = Context.Database.SqlQuery<PropiedadesDto>(sqlq);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool BajaPropiedades(string email) {
|
||||||
|
var con = Context;
|
||||||
|
try {
|
||||||
|
IQueryable<Propiedade> listprop = con.Propiedades.Where(x=>x.DnipropietarioNavigation.Email == email);
|
||||||
|
foreach (var item in listprop) {
|
||||||
|
item.Idestado = 3;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -119,4 +119,62 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Entidades.Admin.UsuarioAdmin> GetClientes(){
|
||||||
|
var con = Context;
|
||||||
|
var list = con.Clientes.ToList().Select(x => new Entidades.Admin.UsuarioAdmin {
|
||||||
|
Dni = x.Dni,
|
||||||
|
Email = x.Email,
|
||||||
|
Nombre = x.Nombre+" "+x.Apellido,
|
||||||
|
Habilitado = x.Habilitado});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AñadirClienteAGrupo(string email, string grupo) {
|
||||||
|
var con = Context;
|
||||||
|
|
||||||
|
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||||
|
var gru = con.Grupos.FirstOrDefault(x => x.Nombre == grupo);
|
||||||
|
|
||||||
|
if (cli == null || gru == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.Idgrupos.Add(gru);
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EliminarClienteAGrupo(string email, string grupo) {
|
||||||
|
var con = Context;
|
||||||
|
|
||||||
|
var cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Email == email);
|
||||||
|
var gru = con.Grupos.FirstOrDefault(x => x.Nombre == grupo);
|
||||||
|
|
||||||
|
if (cli == null || gru == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cli.Idgrupos.Remove(gru);
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool BajaCliente(long dni) {
|
||||||
|
var con = Context;
|
||||||
|
|
||||||
|
Cliente? cli = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Dni == dni);
|
||||||
|
if (cli == null) return false;
|
||||||
|
|
||||||
|
if (cli.Habilitado == 0) {
|
||||||
|
cli.Habilitado = 1;
|
||||||
|
} else {
|
||||||
|
cli.Habilitado = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Guardar(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cliente? ObtenerClientePorDni(long dni) {
|
||||||
|
var con = Context;
|
||||||
|
Cliente? cli = con.Clientes.FirstOrDefault(x=>x.Dni == dni);
|
||||||
|
return cli;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user