FuncionesPropietario #24
@@ -1,6 +1,5 @@
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
@@ -33,18 +32,17 @@ public class PropiedadesController: ControllerBase {
|
||||
|
||||
[HttpGet("api/propiedades/Propietario")]
|
||||
public IActionResult ObtenerPropiedadesPorPropietario (
|
||||
[FromBody] string email,
|
||||
[FromHeader(Name = "Email")] string email,
|
||||
[FromHeader(Name = "Auth")] string Auth) {
|
||||
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 12);
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
email = email.Trim();
|
||||
if (String.IsNullOrEmpty(email)) return BadRequest(new {message ="falta campo email"});
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email);
|
||||
|
||||
IQueryable<PropiedadesDto> ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email);
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
@@ -76,14 +74,16 @@ public class PropiedadesController: ControllerBase {
|
||||
}
|
||||
|
||||
[HttpDelete("api/propiedad")]
|
||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth){
|
||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth, [FromHeader(Name = "Email")] string email){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 2);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
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"});
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id);
|
||||
Cliente? propie = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(email);
|
||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id, propie);
|
||||
|
||||
return ret ?
|
||||
Ok(new {message = $"la propiedad con id {id} fue dada de baja"}):
|
||||
@@ -147,4 +147,4 @@ public class PropiedadesController: ControllerBase {
|
||||
return ret;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ public class PropiedadesDto {
|
||||
public int id { get; set; }
|
||||
public string Ubicacion { get; set; } = "";
|
||||
public int canthabitaciones { get; set; }
|
||||
public string piso { get; set; } = "";
|
||||
public int piso { get; set; }
|
||||
public string letra { get; set; } = "";
|
||||
public string TipoPropiedad { get; set; } = "";
|
||||
}
|
||||
public string Tipo { get; set; } = "";
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import InfoPage from './paginas/info.svelte';
|
||||
import InqPage from "./paginas/inquilino.svelte";
|
||||
import PropPage from "./paginas/propietario.svelte";
|
||||
import MisPropiedades from "./paginas/MisPropiedades.svelte";
|
||||
import FrontAdmin from "./paginas/grupos/AdminG.svelte";
|
||||
import FrontInformes from "./paginas/grupos/InformesG.svelte";
|
||||
import FrontInquilino from "./paginas/grupos/InquilinoG.svelte";
|
||||
@@ -43,6 +44,12 @@
|
||||
<ProteRoute componente={PropPage}/>
|
||||
</Route>
|
||||
|
||||
<!--Mis Propiedades-->
|
||||
<Route path="/accion/2">
|
||||
<ProteRoute componente={MisPropiedades}/>
|
||||
</Route>
|
||||
|
||||
<!--Paginas info Grupo-->
|
||||
<Route path="/grupo/Inquilino">
|
||||
<ProteRoute componente={FrontInquilino}/>
|
||||
</Route>
|
||||
@@ -56,5 +63,7 @@
|
||||
<ProteRoute componente={FrontInformes}/>
|
||||
</Route>
|
||||
|
||||
|
||||
|
||||
</Router>
|
||||
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { Navbar, NavbarBrand, NavbarToggler, NavItem, Nav, NavLink, Collapse } from "@sveltestrap/sveltestrap";
|
||||
import { Navbar, NavbarBrand, NavbarToggler, Nav, Collapse } from "@sveltestrap/sveltestrap";
|
||||
import { onMount } from "svelte";
|
||||
import { writable } from 'svelte/store';
|
||||
import './css/popup.css';
|
||||
import type { Grupo } from "../types";
|
||||
let isOpen: boolean = $state(false);
|
||||
|
||||
type Permiso = {
|
||||
id: number;
|
||||
descripcion: string;
|
||||
};
|
||||
|
||||
type Grupo = {
|
||||
id: number;
|
||||
nombre: string;
|
||||
idpermisos: Permiso[];
|
||||
};
|
||||
|
||||
const permisos = writable<Grupo[]>([]);
|
||||
const email = localStorage.getItem('email');
|
||||
const token = sessionStorage.getItem('token');
|
||||
|
||||
50
Front/src/Componentes/RowPropiedad.svelte
Normal file
50
Front/src/Componentes/RowPropiedad.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import type {PropiedadDto} from "../types"
|
||||
import ModalEstatico from "./ModalEstatico.svelte";
|
||||
let { id, ubicacion, tipo, letra, piso }: PropiedadDto = $props();
|
||||
|
||||
let modal: boolean = $state(false)
|
||||
let modalpayload: string = $state("")
|
||||
|
||||
async function BajaPropiedad(){
|
||||
modal = false;
|
||||
try {
|
||||
const responce = await fetch("http://localhost:5007/api/propiedad?id="+id, {
|
||||
method: "DELETE",
|
||||
headers:{
|
||||
'Auth' : String(sessionStorage.getItem("token")),
|
||||
'Email' : String(localStorage.getItem("email"))
|
||||
},
|
||||
});
|
||||
|
||||
if (responce.ok){
|
||||
const json = await responce.json();
|
||||
modalpayload = json.message;
|
||||
modal = true;
|
||||
}
|
||||
|
||||
if (!responce.ok) {
|
||||
const json = await responce.json();
|
||||
modalpayload = json.message;
|
||||
modal = true;
|
||||
}
|
||||
}catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<tr>
|
||||
<td>{id}</td>
|
||||
<td>{ubicacion}</td>
|
||||
<td>{letra}</td>
|
||||
<td>{piso}</td>
|
||||
<td>{tipo}</td>
|
||||
<td class="text-end">
|
||||
<button class="btn btn-outline-secondary">Modificar</button>
|
||||
<button class="btn btn-outline-danger" onclick={()=> BajaPropiedad()}>Baja</button>
|
||||
</td>
|
||||
</tr>
|
||||
{#if modal}
|
||||
<ModalEstatico payload={modalpayload}/>
|
||||
{/if}
|
||||
@@ -5,7 +5,6 @@
|
||||
let email = $state("")
|
||||
let contraseña = $state("")
|
||||
let errorMessage = $state("")
|
||||
let showAlert = false;
|
||||
|
||||
// @ts-ignore
|
||||
async function submitForm(event) {
|
||||
@@ -25,7 +24,6 @@
|
||||
if (!response.ok){
|
||||
const errorData = await response.json()
|
||||
errorMessage = errorData.message;
|
||||
showAlert = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
62
Front/src/paginas/MisPropiedades.svelte
Normal file
62
Front/src/paginas/MisPropiedades.svelte
Normal file
@@ -0,0 +1,62 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte" ;
|
||||
import { writable } from 'svelte/store';
|
||||
import RowPropiedad from "../Componentes/RowPropiedad.svelte";
|
||||
import type { PropiedadDto } from "../types";
|
||||
|
||||
let propiedades = writable<PropiedadDto[]>([]);
|
||||
let email = localStorage.getItem("email");
|
||||
let token = sessionStorage.getItem("token");
|
||||
|
||||
let fallo: boolean = $state(false);
|
||||
|
||||
onMount(async ()=> {
|
||||
try {
|
||||
const responce = await fetch("http://localhost:5007/api/propiedades/Propietario", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Auth': String(token),
|
||||
'Email' : String(email),
|
||||
'Content-Type' : "application/json"
|
||||
},
|
||||
});
|
||||
if (responce.ok){
|
||||
const json = await responce.json();
|
||||
propiedades.set(json);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!responce.ok){
|
||||
fallo = true;
|
||||
}
|
||||
} catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
<div class="container table-responsive">
|
||||
<table class="table-responsive table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>ubicacion</th>
|
||||
<th>Letra</th>
|
||||
<th>Piso</th>
|
||||
<th>Tipo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each $propiedades as propiedad}
|
||||
{@debug propiedad}
|
||||
<RowPropiedad id={propiedad.id} ubicacion={propiedad.ubicacion} letra={propiedad.letra} piso={propiedad.piso} tipo={propiedad.tipo}/>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{#if fallo}
|
||||
<div class="container alert alert-danger">Fallo al intentar Obtener la lista de propiedades</div>
|
||||
{/if}
|
||||
@@ -2,6 +2,7 @@
|
||||
import { writable } from "svelte/store"; // Importar writable para los estados
|
||||
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
|
||||
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
|
||||
type Propiedad = {
|
||||
ubicacion: string,
|
||||
@@ -51,73 +52,85 @@
|
||||
<NavBarAutocompletable />
|
||||
|
||||
|
||||
<div class="container mt-4">
|
||||
<h2>Registrar Propiedad</h2>
|
||||
<form class="card card-body" onsubmit={submitForm}>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="ubicacion"
|
||||
class="form-control"
|
||||
bind:value={propiedad.ubicacion}
|
||||
placeholder="Ubicación"
|
||||
required
|
||||
/>
|
||||
<label for="ubicacion">Ubicación</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="number"
|
||||
id="canthabitaciones"
|
||||
class="form-control"
|
||||
bind:value={propiedad.canthabitaciones}
|
||||
min="1"
|
||||
placeholder="Cantidad de Habitaciones"
|
||||
required
|
||||
/>
|
||||
<label for="canthabitaciones">Cantidad de Habitaciones</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="number"
|
||||
id="piso"
|
||||
class="form-control"
|
||||
bind:value={propiedad.piso}
|
||||
min="0"
|
||||
placeholder="Piso"
|
||||
/>
|
||||
<label for="piso">Piso</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="letra"
|
||||
class="form-control"
|
||||
bind:value={propiedad.letra}
|
||||
maxlength="1"
|
||||
placeholder="Letra"
|
||||
/>
|
||||
<label for="letra">Letra</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<select
|
||||
id="idtipropiedad"
|
||||
class="form-select"
|
||||
bind:value={propiedad.idtipropiedad}
|
||||
required
|
||||
>
|
||||
<option value="1">Casa</option>
|
||||
<option value="2">Piso</option>
|
||||
<option value="3">Departamento</option>
|
||||
<option value="4">Galpon</option>
|
||||
<option value="5">LocalComercial</option>
|
||||
<option value="6">Oficina</option>
|
||||
</select>
|
||||
<label for="idtipropiedad">Tipo de Propiedad</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Enviar</button>
|
||||
</form>
|
||||
<div class="container-fluid mt-4 row">
|
||||
|
||||
<div class="col-sm">
|
||||
<BarraHorizontalConTexto text={"Formulario Alta propiedad"}/>
|
||||
Este es un formulario con el objetivo de que usted pueda registrar las propiedades <b>suyas</b> que quiera hacer visibles a las busquedas de inquilinos.
|
||||
<br><br>
|
||||
|
||||
<BarraHorizontalConTexto text={"Indicaciones"}/>
|
||||
Para poder cargar la propiedad deberá especificar su ubicacion, la cantidad de habitaciones que posée, en caso de ser un edificio el piso, y letra, y que tipo de propiedad és (casa, departamento, oficina...).
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<h2>Registrar Propiedad</h2>
|
||||
<form class="card card-body" onsubmit={submitForm}>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="ubicacion"
|
||||
class="form-control"
|
||||
bind:value={propiedad.ubicacion}
|
||||
placeholder="Ubicación"
|
||||
required
|
||||
/>
|
||||
<label for="ubicacion">Ubicación</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="number"
|
||||
id="canthabitaciones"
|
||||
class="form-control"
|
||||
bind:value={propiedad.canthabitaciones}
|
||||
min="1"
|
||||
placeholder="Cantidad de Habitaciones"
|
||||
required
|
||||
/>
|
||||
<label for="canthabitaciones">Cantidad de Habitaciones</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="number"
|
||||
id="piso"
|
||||
class="form-control"
|
||||
bind:value={propiedad.piso}
|
||||
min="0"
|
||||
placeholder="Piso"
|
||||
/>
|
||||
<label for="piso">Piso</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input
|
||||
type="text"
|
||||
id="letra"
|
||||
class="form-control"
|
||||
bind:value={propiedad.letra}
|
||||
maxlength="1"
|
||||
placeholder="Letra"
|
||||
/>
|
||||
<label for="letra">Letra</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<select
|
||||
id="idtipropiedad"
|
||||
class="form-select"
|
||||
bind:value={propiedad.idtipropiedad}
|
||||
required
|
||||
>
|
||||
<option value="1">Casa</option>
|
||||
<option value="2">Piso</option>
|
||||
<option value="3">Departamento</option>
|
||||
<option value="4">Galpon</option>
|
||||
<option value="5">LocalComercial</option>
|
||||
<option value="6">Oficina</option>
|
||||
</select>
|
||||
<label for="idtipropiedad">Tipo de Propiedad</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Enviar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{#if mostrarModal == true}
|
||||
<ModalEstatico payload={datosModal} />
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
<div class="container">
|
||||
<div class="container-fluid">
|
||||
<div class="row align-items-start">
|
||||
<div class="col">
|
||||
<div class="col-sm">
|
||||
<br><br>
|
||||
<TextBar text="Formulario Alta Inquilino" />
|
||||
Este es un formulario para crear una cuenta de Propietario.
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
<NavBarAutocompletable/>
|
||||
|
||||
<div class="container">
|
||||
<div class="container-fluid">
|
||||
<div class="row align-items-start">
|
||||
<div class="col">
|
||||
<div class="col-sm">
|
||||
<br><br>
|
||||
<TextBar text="Formulario Alta Propietario" />
|
||||
Este es un formulario para crear una cuenta de Inquilino.
|
||||
|
||||
17
Front/src/types.d.ts
vendored
Normal file
17
Front/src/types.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export type PropiedadDto = {
|
||||
id: number,
|
||||
ubicacion: string,
|
||||
tipo: string,
|
||||
piso: string | null,
|
||||
letra: string | null,
|
||||
}
|
||||
export type Permiso = {
|
||||
id: number;
|
||||
descripcion: string;
|
||||
};
|
||||
|
||||
export type Grupo = {
|
||||
id: number;
|
||||
nombre: string;
|
||||
idpermisos: Permiso[];
|
||||
};
|
||||
@@ -7,8 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
||||
{
|
||||
public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades> {
|
||||
|
||||
public IQueryable<PropiedadesDto> ListarPropiedades(){
|
||||
FormattableString sqlq = $"""
|
||||
@@ -69,10 +68,10 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
||||
|
||||
public IQueryable<PropiedadesDto> ObtenerPropiedadesPorEmail(string email) {
|
||||
FormattableString sqlq = $"""
|
||||
SELECT p.id, p.ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as TipoPropiedad From Propiedades p
|
||||
SELECT p.id, p.ubicacion as Ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion as Tipo From Propiedades p
|
||||
JOIN Clientes c ON c.dni = p.dnipropietario
|
||||
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
||||
WHERE c.email = {email}
|
||||
WHERE c.email = {email} AND p.idestado = 1
|
||||
""";
|
||||
var ret = Context.Database.SqlQuery<PropiedadesDto>(sqlq);
|
||||
return ret;
|
||||
@@ -93,10 +92,14 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool BajaPropiedad(int id) {
|
||||
public bool BajaPropiedad(int id, Cliente? cli) {
|
||||
if (cli == null) return false;
|
||||
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.Find(id);
|
||||
Propiedade? prop = con.Propiedades.FirstOrDefault(x=>x.Id == id);
|
||||
if (prop == null) return false;
|
||||
Console.WriteLine("prop.dni: "+prop.Dnipropietario+", cli.dni: "+cli.Dni);
|
||||
if (prop.Dnipropietario != cli.Dni) return false;
|
||||
prop.Idestado = 3;
|
||||
|
||||
return Guardar(con);
|
||||
@@ -121,4 +124,4 @@ public bool AñadirPropiedad(Propiedade? prop) {
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user