acciones_admin #14
@@ -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
|
||||
@@ -1,8 +1,16 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,6 @@ namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class PropietarioController: ControllerBase {
|
||||
|
||||
[HttpGet("api/propietario")]
|
||||
public IActionResult ListarPropietarios([FromHeader(Name = "Auth")] string Auth) {
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("api/propietarios")]
|
||||
public IActionResult AltaPropietario([FromBody]CrearClienteDto Propietario,[FromHeader(Name = "Auth")] string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -38,6 +33,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 = "";
|
||||
|
||||
|
||||
9
Entidades/Dto/PropiedadDto.cs
Normal file
9
Entidades/Dto/PropiedadDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Entidades.Dto;
|
||||
public class PropiedadDto {
|
||||
public string Ubicacion { get; set; } = null!;
|
||||
public int Canthabitaciones { get; set; }
|
||||
public int? Piso { get; set; }
|
||||
public string? Letra { get; set; }
|
||||
public string Email { get; set; }
|
||||
public int Idtipropiedad { get; set; }
|
||||
}
|
||||
@@ -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,22 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
||||
{
|
||||
public IQueryable<Propiedade> ListarPropiedades(){
|
||||
var con = Context;
|
||||
return con.Propiedades.AsQueryable();
|
||||
}
|
||||
|
||||
public bool AñadirPropiedad(){
|
||||
return false;
|
||||
public bool AñadirPropiedad(Propiedade prop){
|
||||
var con = Context;
|
||||
|
||||
int count = con.Propiedades.Count()+1;
|
||||
|
||||
prop.Id = count;
|
||||
prop.Idestado = 1;
|
||||
con.Propiedades.Add(prop);
|
||||
return Guardar(con);
|
||||
}
|
||||
}
|
||||
13
Modelo/RepositorioPropietario.cs
Normal file
13
Modelo/RepositorioPropietario.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Entidades;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Modelo;
|
||||
|
||||
public class RepositorioPropietario: RepositorioBase<RepositorioPropietario> {
|
||||
public Cliente? ObtenerClientePorEmail(string email){
|
||||
var con = Context;
|
||||
|
||||
Cliente? cli = con.Clientes.FirstOrDefault(c => c.Email == email);
|
||||
return cli;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,9 +7,8 @@ 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 +33,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 +56,16 @@ 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;
|
||||
|
||||
cliOld = cli;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool CheckUsuario(LoginDto logindto) {
|
||||
|
||||
string Contraseña = HacerHash(logindto.Contraseña);
|
||||
@@ -71,12 +79,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 +95,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