Propiedades_abm #11
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
|
||||
<PackageReference Include="minio" Version="6.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
25
Aspnet/Aspnet.sln
Normal file
25
Aspnet/Aspnet.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlquilaFacil", "AlquilaFacil.csproj", "{76BA8B31-BAD3-49CD-B8B8-BE22D8AEA281}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{76BA8B31-BAD3-49CD-B8B8-BE22D8AEA281}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{76BA8B31-BAD3-49CD-B8B8-BE22D8AEA281}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{76BA8B31-BAD3-49CD-B8B8-BE22D8AEA281}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{76BA8B31-BAD3-49CD-B8B8-BE22D8AEA281}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CF93AFAC-32EF-4993-84A2-CA2EB32F58FF}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -7,10 +7,10 @@ namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class AccionesController: ControllerBase {
|
||||
|
||||
//Reutilizo el loginDto pero no lleno el campo de contraseña
|
||||
[HttpPost("api/acciones")]
|
||||
public IActionResult ListarAccionesPorUsuario([FromBody] LoginDto email, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (email.Email == "" || email.Email == null) return BadRequest();
|
||||
|
||||
|
||||
if (Auth == "") return Unauthorized(new { esValido = false});
|
||||
|
||||
|
||||
@@ -1,8 +1,150 @@
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class PropiedadesController: ControllerBase {
|
||||
[HttpGet("api/propiedades")]
|
||||
public IActionResult ListarPropietarios([FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.ListarPropiedades();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpGet("api/propiedad")]
|
||||
public IActionResult ObtenerPropiedadPorId(int Id, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (Id < 0) return BadRequest("la id de propiedad no puede ser negativa");
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadPorId(Id);
|
||||
if (ret == null) return BadRequest("No existe la propiedad");
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpGet("api/propiedades/Propietario")]
|
||||
public IActionResult ObtenerPropiedadesPorPropietario(
|
||||
[FromBody] string email,
|
||||
[FromHeader(Name = "Auth")] string Auth) {
|
||||
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
email = email.Trim();
|
||||
if (String.IsNullOrEmpty(email)) return BadRequest("falta campo email");
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.ObtenerPropiedadesPorEmail(email);
|
||||
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpPost("api/propiedad")]
|
||||
public IActionResult AltaPropiedad([FromBody] AltaPropiedadDto propiedad, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
string validacion2 = ValidarPropiedad(propiedad);
|
||||
if (validacion2 != "") return BadRequest(new { message = validacion2 });
|
||||
|
||||
Cliente? cli = RepositorioPropietario.Singleton.ObtenerPropietarioPorEmail(propiedad.Email);
|
||||
if (cli == null) return BadRequest("El email no corresponde a un propietario");
|
||||
|
||||
Propiedade Prop = new Propiedade{
|
||||
Canthabitaciones = propiedad.Canthabitaciones,
|
||||
Dnipropietario = cli.Dni,
|
||||
Idtipropiedad = propiedad.Idtipropiedad,
|
||||
Ubicacion = propiedad.Ubicacion,
|
||||
Letra = propiedad.Letra != null ? propiedad.Letra : null,
|
||||
Piso = propiedad.Piso != null ? propiedad.Piso : null,
|
||||
};
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.AñadirPropiedad(Prop);
|
||||
return (ret)?
|
||||
Ok("Fue Cargado Correctamente") :
|
||||
BadRequest("Fallo al momento de añadir la propiedad a la base de datos");
|
||||
}
|
||||
|
||||
[HttpDelete("api/propiedad")]
|
||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (id <= 0) return BadRequest("No es una id valida");
|
||||
|
||||
var ret = RepositorioPropiedades.Singleton.BajaPropiedad(id);
|
||||
|
||||
return ret ?
|
||||
Ok(new {message = $"la propiedad con id {id} fue dada de baja"}):
|
||||
BadRequest("Fallo al dar de baja la propiedad");
|
||||
}
|
||||
|
||||
[HttpPut("api/propiedades/addServicio")]
|
||||
public IActionResult AñadirServicio([FromBody] ServicioAPropiedadDto Servicios, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (Servicios.propiedadid <= 0) return BadRequest("No puede tener una id negativa o cero");
|
||||
if (Servicios.idServicios.Count() < 1) return BadRequest("Falta añadir servicios");
|
||||
if (Servicios.idServicios.Any(x => x<= 0)) return BadRequest("No tienen haber ids negativas o cero de servicio");
|
||||
|
||||
var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(Servicios.propiedadid);
|
||||
|
||||
bool validacion2 = Servicios.idServicios.Any(x => serv.Contains(x));
|
||||
|
||||
if (validacion2 == true) return BadRequest("Hay elementos repetidos");
|
||||
|
||||
bool ret = RepositorioPropiedades.
|
||||
Singleton.AñadirServicioAPropiedad(Servicios.propiedadid, Servicios.idServicios);
|
||||
|
||||
return ret ?
|
||||
Ok("Los Servicios Se Cargaron correctamente a la propiedad") : BadRequest("No se pudo Cargar los Servicios a la propiedad");
|
||||
|
||||
}
|
||||
|
||||
[HttpPut("api/propiedades/RmServicio")]
|
||||
public IActionResult EliminarServicio([FromBody] ServicioAPropiedadDto servicio, [FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
if (servicio.propiedadid <= 0) return BadRequest("No puede tener una id negativa o cero");
|
||||
if (servicio.idServicios.Count() < 1) return BadRequest("Falta añadir servicios");
|
||||
if (servicio.idServicios.Any(x => x<= 0)) return BadRequest("No tienen haber ids negativas o cero de servicio");
|
||||
|
||||
var serv = RepositorioServicios.Singleton.ObtenerServiciosPorPropiedad(servicio.propiedadid);
|
||||
|
||||
var repetidos = serv.Intersect(servicio.idServicios);
|
||||
|
||||
bool ret = RepositorioPropiedades.Singleton.BajaServiciosAPropiedad(servicio.propiedadid, servicio.idServicios);
|
||||
|
||||
return ret ?
|
||||
Ok("Se Eliminaron los servicios seleccionados de la propiedad") : BadRequest("Fallo al eliminarse los servicios de la propiedad");
|
||||
|
||||
}
|
||||
|
||||
private string ValidarPropiedad(AltaPropiedadDto prop) {
|
||||
if (prop == null) return "Esta mal formado el body de la request";
|
||||
|
||||
string ret = "";
|
||||
if (String.IsNullOrEmpty(prop.Email)) ret += "Falta Definir un email de propietario\n";
|
||||
if (prop.Canthabitaciones < 0) ret += "No se puede tener una cantidad de habitaciones negativa\n";
|
||||
if (prop.Idtipropiedad <= 0) ret += "No tiene un tipo de propiedad asociada";
|
||||
if (String.IsNullOrEmpty(prop.Ubicacion)) ret += "Tiene que definir la ubicacion de la propiedad\n";
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
@@ -11,12 +12,18 @@ namespace AlquilaFacil.Controllers;
|
||||
public class PropietarioController: ControllerBase {
|
||||
|
||||
[HttpGet("api/propietario")]
|
||||
public IActionResult ListarPropietarios([FromHeader(Name = "Auth")] string Auth) {
|
||||
return Ok();
|
||||
public IActionResult ObtenerPropietarioPorDni(long Dni, [FromHeader(Name ="Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
var ret = RepositorioPropietario.Singleton.ObtenerPropietarioPorDni(Dni);
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpPost("api/propietarios")]
|
||||
public IActionResult AltaPropietario([FromBody]CrearClienteDto Propietario,[FromHeader(Name = "Auth")] string Auth) {
|
||||
public IActionResult AltaPropietario([FromBody]CrearClienteDto Propietario,
|
||||
[FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
@@ -38,6 +45,30 @@ public class PropietarioController: ControllerBase {
|
||||
return ret ?
|
||||
Ok(new {message = "Se añadio el propietario exitosamente"}) : BadRequest();
|
||||
}
|
||||
|
||||
[HttpPatch("api/propietarios")]
|
||||
public IActionResult PatchPropietario([FromBody]CrearClienteDto Propietario, [FromHeader(Name = "Auth")] string Auth){
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
string validacion2 = verificarCrearUsuario(Propietario);
|
||||
if (validacion2 != "") return BadRequest(validacion2);
|
||||
|
||||
var cli = new Cliente {
|
||||
Dni = Propietario.dni,
|
||||
Nombre = Propietario.nombre,
|
||||
Domicilio = Propietario.domicilio,
|
||||
Apellido = Propietario.apellido,
|
||||
Celular = Propietario.celular,
|
||||
Email = Propietario.email,
|
||||
Contraseña = Encoding.UTF8.GetBytes(HacerHash(Propietario.contraseña))
|
||||
};
|
||||
var ret = RepositorioUsuarios.Singleton.ActualizarPropietario(cli);
|
||||
return ret ?
|
||||
Ok(new {message = "Se Modifico el propietario exitosamente"}) : BadRequest();
|
||||
}
|
||||
|
||||
private string verificarCrearUsuario(CrearClienteDto cid) {
|
||||
string msg = "";
|
||||
|
||||
|
||||
12
Aspnet/Controllers/ServiciosController.cs
Normal file
12
Aspnet/Controllers/ServiciosController.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Modelo;
|
||||
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class ServiciosController: ControllerBase {
|
||||
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
run:
|
||||
dotnet watch run
|
||||
dotnet watch run --project AlquilaFacil.csproj
|
||||
|
||||
@@ -23,6 +23,8 @@ public partial class AlquilaFacilContext : DbContext
|
||||
|
||||
public virtual DbSet<Defecto> Defectos { get; set; }
|
||||
|
||||
public virtual DbSet<EstadoPropiedad> EstadoPropiedads { get; set; }
|
||||
|
||||
public virtual DbSet<Estadodefecto> Estadodefectos { get; set; }
|
||||
|
||||
public virtual DbSet<Estadoventa> Estadoventas { get; set; }
|
||||
@@ -37,6 +39,8 @@ public partial class AlquilaFacilContext : DbContext
|
||||
|
||||
public virtual DbSet<Recibo> Recibos { get; set; }
|
||||
|
||||
public virtual DbSet<Servicio> Servicios { get; set; }
|
||||
|
||||
public virtual DbSet<TipoPropiedad> TipoPropiedads { get; set; }
|
||||
|
||||
public virtual DbSet<Venta> Ventas { get; set; }
|
||||
@@ -99,6 +103,10 @@ public partial class AlquilaFacilContext : DbContext
|
||||
entity.Property(e => e.Email)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("email");
|
||||
entity.Property(e => e.Habilitado)
|
||||
.HasDefaultValueSql("b'1'")
|
||||
.HasColumnType("bit(1)")
|
||||
.HasColumnName("habilitado");
|
||||
entity.Property(e => e.Nombre)
|
||||
.HasMaxLength(20)
|
||||
.HasColumnName("nombre");
|
||||
@@ -158,6 +166,9 @@ public partial class AlquilaFacilContext : DbContext
|
||||
entity.Property(e => e.Fechainicio)
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("fechainicio");
|
||||
entity.Property(e => e.Habilitado)
|
||||
.HasColumnType("bit(1)")
|
||||
.HasColumnName("habilitado");
|
||||
entity.Property(e => e.Idpropiedad)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("idpropiedad");
|
||||
@@ -259,6 +270,20 @@ public partial class AlquilaFacilContext : DbContext
|
||||
.HasConstraintName("FK_DEF_EST");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EstadoPropiedad>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity.ToTable("EstadoPropiedad");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Descripcion)
|
||||
.HasMaxLength(11)
|
||||
.HasColumnName("descripcion");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Estadodefecto>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
@@ -385,6 +410,8 @@ public partial class AlquilaFacilContext : DbContext
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity.HasIndex(e => e.Idestado, "FK_PROP_EST");
|
||||
|
||||
entity.HasIndex(e => e.Dnipropietario, "FK_PROP_PROPI");
|
||||
|
||||
entity.HasIndex(e => e.Idtipropiedad, "FK_PROP_TIPO");
|
||||
@@ -398,6 +425,9 @@ public partial class AlquilaFacilContext : DbContext
|
||||
entity.Property(e => e.Dnipropietario)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("dnipropietario");
|
||||
entity.Property(e => e.Idestado)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("idestado");
|
||||
entity.Property(e => e.Idtipropiedad)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("idtipropiedad");
|
||||
@@ -417,6 +447,11 @@ public partial class AlquilaFacilContext : DbContext
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("FK_PROP_PROPI");
|
||||
|
||||
entity.HasOne(d => d.IdestadoNavigation).WithMany(p => p.Propiedades)
|
||||
.HasForeignKey(d => d.Idestado)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("FK_PROP_EST");
|
||||
|
||||
entity.HasOne(d => d.IdtipropiedadNavigation).WithMany(p => p.Propiedades)
|
||||
.HasForeignKey(d => d.Idtipropiedad)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
@@ -440,6 +475,42 @@ public partial class AlquilaFacilContext : DbContext
|
||||
.HasColumnName("monto");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Servicio>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Descripcion)
|
||||
.HasMaxLength(20)
|
||||
.HasColumnName("descripcion");
|
||||
|
||||
entity.HasMany(d => d.IdPropiedads).WithMany(p => p.IdServicios)
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"ServicioPropiedad",
|
||||
r => r.HasOne<Propiedade>().WithMany()
|
||||
.HasForeignKey("IdPropiedad")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("Servicio_Propiedad_ibfk_2"),
|
||||
l => l.HasOne<Servicio>().WithMany()
|
||||
.HasForeignKey("IdServicio")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("Servicio_Propiedad_ibfk_1"),
|
||||
j =>
|
||||
{
|
||||
j.HasKey("IdServicio", "IdPropiedad").HasName("PRIMARY");
|
||||
j.ToTable("Servicio_Propiedad");
|
||||
j.HasIndex(new[] { "IdPropiedad" }, "idPropiedad");
|
||||
j.IndexerProperty<int>("IdServicio")
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("idServicio");
|
||||
j.IndexerProperty<int>("IdPropiedad")
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("idPropiedad");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TipoPropiedad>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("PRIMARY");
|
||||
|
||||
@@ -21,6 +21,8 @@ public partial class Cliente
|
||||
|
||||
public string? Token { get; set; }
|
||||
|
||||
public ulong Habilitado { get; set; }
|
||||
|
||||
public virtual ICollection<Contrato> ContratoDniinquilinoNavigations { get; set; } = new List<Contrato>();
|
||||
|
||||
public virtual ICollection<Contrato> ContratoDnipropietarioNavigations { get; set; } = new List<Contrato>();
|
||||
|
||||
@@ -25,6 +25,8 @@ public partial class Contrato
|
||||
|
||||
public long? Idventa { get; set; }
|
||||
|
||||
public ulong Habilitado { get; set; }
|
||||
|
||||
public virtual ICollection<Defecto> Defectos { get; set; } = new List<Defecto>();
|
||||
|
||||
public virtual Cliente? DniinquilinoNavigation { get; set; }
|
||||
|
||||
9
Entidades/Dto/AltaPropiedadDto.cs
Normal file
9
Entidades/Dto/AltaPropiedadDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Entidades.Dto;
|
||||
public class AltaPropiedadDto {
|
||||
public string Ubicacion { get; set; } = null!;
|
||||
public int Canthabitaciones { get; set; }
|
||||
public int? Piso { get; set; } = null;
|
||||
public string? Letra { get; set; } = null;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int Idtipropiedad { get; set; }
|
||||
}
|
||||
9
Entidades/Dto/PropiedadesDto.cs
Normal file
9
Entidades/Dto/PropiedadesDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Entidades.Dto;
|
||||
public class PropiedadesDto {
|
||||
public int id { get; set; }
|
||||
public string Ubicacion { get; set; } = "";
|
||||
public int canthabitaciones { get; set; }
|
||||
public string piso { get; set; } = "";
|
||||
public string letra { get; set; } = "";
|
||||
public string TipoPropiedad { get; set; } = "";
|
||||
}
|
||||
2
Entidades/Dto/ServicioAPropiedadDto.cs
Normal file
2
Entidades/Dto/ServicioAPropiedadDto.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
namespace Entidades.Dto;
|
||||
public record ServicioAPropiedadDto(int propiedadid, List<int> idServicios);
|
||||
13
Entidades/Estadopropiedad.cs
Normal file
13
Entidades/Estadopropiedad.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Entidades;
|
||||
|
||||
public partial class EstadoPropiedad
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Descripcion { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Propiedade> Propiedades { get; set; } = new List<Propiedade>();
|
||||
}
|
||||
@@ -19,11 +19,17 @@ public partial class Propiedade
|
||||
|
||||
public int Idtipropiedad { get; set; }
|
||||
|
||||
public int? Idestado { get; set; }
|
||||
|
||||
public virtual ICollection<Contrato> Contratos { get; set; } = new List<Contrato>();
|
||||
|
||||
public virtual Cliente? DnipropietarioNavigation { get; set; }
|
||||
|
||||
public virtual EstadoPropiedad? IdestadoNavigation { get; set; }
|
||||
|
||||
public virtual TipoPropiedad IdtipropiedadNavigation { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Venta> Venta { get; set; } = new List<Venta>();
|
||||
|
||||
public virtual ICollection<Servicio> IdServicios { get; set; } = new List<Servicio>();
|
||||
}
|
||||
|
||||
15
Entidades/Servicio.cs
Normal file
15
Entidades/Servicio.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Entidades;
|
||||
|
||||
public partial class Servicio
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Descripcion { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<Propiedade> IdPropiedads { get; set; } = new List<Propiedade>();
|
||||
}
|
||||
@@ -7,11 +7,11 @@ namespace Modelo;
|
||||
public abstract class RepositorioBase<S>
|
||||
where S : new()
|
||||
{
|
||||
protected AlquilaFacilContext Context { get{ return new AlquilaFacilContext();}}
|
||||
protected AlquilaFacilContext Context { get { return new AlquilaFacilContext(); }}
|
||||
private static readonly S instance = new();
|
||||
public static S Singleton { get{return instance;}}
|
||||
public static S Singleton { get { return instance; }}
|
||||
|
||||
public bool Guardar(AlquilaFacilContext context){
|
||||
public bool Guardar(AlquilaFacilContext context) {
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -8,7 +8,9 @@ public class RepositorioInquilinos: RepositorioBase<RepositorioInquilinos> {
|
||||
{
|
||||
FormattableString sqlq =
|
||||
$"""
|
||||
SELECT I.Dni, I.Nombre, I.Apellido FROM Inquilinos
|
||||
SELECT I.Dni, I.Nombre, I.Apellido FROM Clientes I
|
||||
JOIN cliente_Grupos cg on cg.idcliente = I.Dni
|
||||
WHERE cg.idgrupo = 2;
|
||||
""";
|
||||
return Context.Database.SqlQuery<InquilinoDto>(sqlq);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,104 @@
|
||||
using System;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Entidades;
|
||||
using Entidades.Dto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
||||
{
|
||||
|
||||
public bool AñadirPropiedad(){
|
||||
return false;
|
||||
public IQueryable<PropiedadesDto> ListarPropiedades(){
|
||||
FormattableString sqlq = $"""
|
||||
SELECT p.id, p.ubicacion, p.canthabitaciones, p.piso, p.letra, tp.descripcion AS TipoPropiedad FROM Propiedades p
|
||||
JOIN EstadoPropiedad ep ON p.idestado = 1
|
||||
JOIN TipoPropiedad tp ON p.idtipropiedad = tp.id
|
||||
""";
|
||||
|
||||
var ret = Context.Database.SqlQuery<PropiedadesDto>(sqlq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Propiedade? ObtenerPropiedadPorId(int Id) {
|
||||
|
||||
FormattableString sqlq = $"""
|
||||
SELECT * FROM Propiedades p
|
||||
WHERE p.id = {Id}
|
||||
LIMIT 1
|
||||
""";
|
||||
|
||||
Propiedade? prop = Context.Database.SqlQuery<Propiedade>(sqlq).First();
|
||||
if (prop == null || prop.Id == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
public bool AñadirPropiedad(Propiedade? prop){
|
||||
if (prop == null) return false;
|
||||
|
||||
var con = Context;
|
||||
|
||||
int count = con.Propiedades.Count()+1;
|
||||
|
||||
prop.Id = count;
|
||||
prop.Idestado = 1;
|
||||
con.Propiedades.Add(prop);
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
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
|
||||
JOIN Clientes c ON c.dni = p.dnipropietario
|
||||
JOIN TipoPropiedad tp ON tp.id = p.idtipropiedad
|
||||
WHERE c.email = {email}
|
||||
""";
|
||||
var ret = Context.Database.SqlQuery<PropiedadesDto>(sqlq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool AñadirServicioAPropiedad(int idprop, List<int> idserv){
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.Find(idprop);
|
||||
if (prop == null) return false;
|
||||
|
||||
foreach (int id in idserv) {
|
||||
Servicio? servicio = con.Servicios.Find(id);
|
||||
if (servicio == null) return false;
|
||||
|
||||
prop.IdServicios.Add(servicio);
|
||||
}
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool BajaPropiedad(int id) {
|
||||
var con = Context;
|
||||
Propiedade prop = con.Propiedades.Find(id);
|
||||
prop.Idestado = 3;
|
||||
|
||||
return Guardar(con);
|
||||
|
||||
}
|
||||
|
||||
public bool BajaServiciosAPropiedad(int idprop, List<int> idserv)
|
||||
{
|
||||
var con = Context;
|
||||
Propiedade? prop = con.Propiedades.Include(x=>x.IdServicios).FirstOrDefault(x => x.Id == idprop);
|
||||
if (prop == null) return false;
|
||||
|
||||
|
||||
foreach (int id in idserv) {
|
||||
Servicio? servicio = con.Servicios.Find(id);
|
||||
if (servicio == null) return false;
|
||||
|
||||
if (prop.IdServicios.Contains(servicio)){
|
||||
prop.IdServicios.Remove(servicio);
|
||||
}
|
||||
}
|
||||
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
40
Modelo/RepositorioPropietario.cs
Normal file
40
Modelo/RepositorioPropietario.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropietario: RepositorioBase<RepositorioPropietario> {
|
||||
public Cliente? ObtenerPropietarioPorDni(long Dni){
|
||||
|
||||
if (Dni < 1) return null;
|
||||
|
||||
FormattableString sqlq = $"""
|
||||
SELECT * FROM Clientes c
|
||||
JOIN cliente_Grupos cg ON cg.idgrupo = 1
|
||||
WHERE c.dni = {Dni}
|
||||
LIMIT 1
|
||||
""";
|
||||
|
||||
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
||||
if (cli == null|| cli.Dni == 0) return null;
|
||||
if (cli.Dni == 0 || cli == null) return null;
|
||||
return cli;
|
||||
|
||||
}
|
||||
|
||||
public Cliente? ObtenerPropietarioPorEmail(string email){
|
||||
|
||||
FormattableString sqlq = $"""
|
||||
SELECT * FROM Clientes c
|
||||
JOIN cliente_Grupos cg ON cg.idgrupo = 1
|
||||
WHERE c.email = {email}
|
||||
LIMIT 1
|
||||
""";
|
||||
|
||||
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
||||
if (cli == null|| cli.Dni == 0) return null;
|
||||
if (cli.Dni == 0 || cli == null) return null;
|
||||
return cli;
|
||||
}
|
||||
}
|
||||
11
Modelo/RepositorioServicios.cs
Normal file
11
Modelo/RepositorioServicios.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Modelo;
|
||||
using Entidades;
|
||||
public class RepositorioServicios: RepositorioBase<RepositorioServicios> {
|
||||
public IQueryable<int> ObtenerServiciosPorPropiedad(int idpropiedad){
|
||||
var con = Context;
|
||||
return con.Propiedades
|
||||
.Where(x => x.Id == idpropiedad)
|
||||
.SelectMany(x => x.IdServicios)
|
||||
.Select(x=>x.Id);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Entidades.Dto;
|
||||
using Entidades;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
|
||||
namespace Modelo;
|
||||
|
||||
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
{
|
||||
public bool AltaInquilino(Cliente cli){
|
||||
public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios> {
|
||||
public bool AltaInquilino(Cliente cli) {
|
||||
var con = Context;
|
||||
|
||||
//check por si la cuenta ya existe (puede ser propietario)
|
||||
@@ -34,8 +31,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
|
||||
}
|
||||
|
||||
public bool AltaPropietario(Cliente cli)
|
||||
{
|
||||
public bool AltaPropietario(Cliente cli) {
|
||||
var con = Context;
|
||||
|
||||
//check por si la cuenta ya existe (puede ser propietario)
|
||||
@@ -58,6 +54,17 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
public bool ActualizarPropietario(Cliente cli) {
|
||||
var con = Context;
|
||||
Cliente? cliOld = con.Clientes.Find(cli.Dni);
|
||||
if (cliOld == null) return false;
|
||||
if (cli.Dni != cliOld.Dni) return false;
|
||||
|
||||
cliOld = cli;
|
||||
return Guardar(con);
|
||||
}
|
||||
|
||||
|
||||
public bool CheckUsuario(LoginDto logindto) {
|
||||
|
||||
string Contraseña = HacerHash(logindto.Contraseña);
|
||||
@@ -71,12 +78,12 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return false;
|
||||
|
||||
}
|
||||
private string HacerHash(string pass){
|
||||
private string HacerHash(string pass) {
|
||||
var buf = SHA256.HashData(Encoding.UTF8.GetBytes(pass));
|
||||
return BitConverter.ToString(buf).Replace("-","");
|
||||
}
|
||||
|
||||
public bool CheckToken(string email, string token){
|
||||
public bool CheckToken(string email, string token) {
|
||||
var usu = Context.Clientes.FirstOrDefault(x => x.Email == email);
|
||||
if (usu == null) return false;
|
||||
|
||||
@@ -87,8 +94,7 @@ public class RepositorioUsuarios: RepositorioBase<RepositorioUsuarios>
|
||||
return usu.Token == token;
|
||||
}
|
||||
|
||||
public void GuardarToken(LoginDto login, string tokenString)
|
||||
{
|
||||
public void GuardarToken(LoginDto login, string tokenString) {
|
||||
var con = Context;
|
||||
var usu = con.Clientes.FirstOrDefault(x => x.Email == login.Email);
|
||||
if (usu == null) return;
|
||||
|
||||
Reference in New Issue
Block a user