feat: primera implementacion propiedades ABM
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
@@ -78,7 +78,7 @@ public class PropiedadesController: ControllerBase {
|
|||||||
[HttpDelete("api/propiedad")]
|
[HttpDelete("api/propiedad")]
|
||||||
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth){
|
public IActionResult BajaPropiedad(int id, [FromHeader(Name = "Auth")] string Auth){
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, "/accion/2");
|
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, Request.Path);
|
||||||
if (validacion1 == false) return Unauthorized();
|
if (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
if (id <= 0) return BadRequest("No es una id valida");
|
if (id <= 0) return BadRequest("No es una id valida");
|
||||||
@@ -90,6 +90,51 @@ public class PropiedadesController: ControllerBase {
|
|||||||
BadRequest("Fallo al dar de baja la propiedad");
|
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) {
|
private string ValidarPropiedad(AltaPropiedadDto prop) {
|
||||||
if (prop == null) return "Esta mal formado el body de la request";
|
if (prop == null) return "Esta mal formado el body de la request";
|
||||||
|
|
||||||
|
|||||||
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 {
|
||||||
|
|
||||||
|
}
|
||||||
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);
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Entidades;
|
namespace Entidades;
|
||||||
|
|
||||||
@@ -9,5 +10,6 @@ public partial class Servicio
|
|||||||
|
|
||||||
public string Descripcion { get; set; } = null!;
|
public string Descripcion { get; set; } = null!;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public virtual ICollection<Propiedade> IdPropiedads { get; set; } = new List<Propiedade>();
|
public virtual ICollection<Propiedade> IdPropiedads { get; set; } = new List<Propiedade>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,21 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
|||||||
return ret;
|
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) {
|
public bool BajaPropiedad(int id) {
|
||||||
var con = Context;
|
var con = Context;
|
||||||
Propiedade prop = con.Propiedades.Find(id);
|
Propiedade prop = con.Propiedades.Find(id);
|
||||||
@@ -67,4 +82,23 @@ public class RepositorioPropiedades: RepositorioBase<RepositorioPropiedades>
|
|||||||
return Guardar(con);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ public class RepositorioPropietario: RepositorioBase<RepositorioPropietario> {
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
||||||
|
if (cli == null|| cli.Dni == 0) return null;
|
||||||
if (cli.Dni == 0 || cli == null) return null;
|
if (cli.Dni == 0 || cli == null) return null;
|
||||||
return cli;
|
return cli;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ public class RepositorioPropietario: RepositorioBase<RepositorioPropietario> {
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
Cliente? cli = Context.Database.SqlQuery<Cliente?>(sqlq).First();
|
||||||
|
if (cli == null|| cli.Dni == 0) return null;
|
||||||
if (cli.Dni == 0 || cli == null) return null;
|
if (cli.Dni == 0 || cli == null) return null;
|
||||||
return cli;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user