lo que hice hoy
This commit is contained in:
35
Aspnet/Builder/DtoBuilder/CanonDtoBuilder.cs
Normal file
35
Aspnet/Builder/DtoBuilder/CanonDtoBuilder.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Entidades.Dto;
|
||||
|
||||
namespace AlquilaFacil.Builder;
|
||||
|
||||
public class CanonDtoBuilder : Builder<CanonDto>{
|
||||
public CanonDtoBuilder SetId(long id) {
|
||||
data.Id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CanonDtoBuilder SetMesNum(int mesNum) {
|
||||
data.MesNum = mesNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CanonDtoBuilder SetMes(DateTime d){
|
||||
data.Mes = d;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CanonDtoBuilder SetMonto(Decimal monto) {
|
||||
data.Monto = monto;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CanonDtoBuilder SetDivisa(string divisa) {
|
||||
data.Divisa = divisa;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CanonDtoBuilder SetPago(bool p) {
|
||||
data.Pago = p;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
75
Aspnet/Builder/DtoBuilder/ContratoPropiedadDtoBuilder.cs
Normal file
75
Aspnet/Builder/DtoBuilder/ContratoPropiedadDtoBuilder.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Entidades.Dto;
|
||||
|
||||
namespace AlquilaFacil.Builder;
|
||||
public class ContratoPropiedadDtoBuilder : Builder<ContratoPropiedadDto>{
|
||||
public ContratoPropiedadDtoBuilder SetId(long id ){
|
||||
data.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetUbicacion(string ub){
|
||||
data.Ubicacion = ub;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetTipo(string tipo){
|
||||
data.TipoPropiedad = tipo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetFechaInicio(DateTime fec) {
|
||||
data.Fechainicio = fec;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetInquilino(string inquilino){
|
||||
data.Inquilino = inquilino;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetPropietario(string propietario){
|
||||
data.Propietario = propietario;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetEstado(ulong habilitado, ulong cancelado) {
|
||||
bool Habilitado = habilitado == 0?false:true;
|
||||
bool Cancelado = cancelado == 0?false:true;
|
||||
|
||||
if (Habilitado == true && Cancelado == false){
|
||||
data.Estado = "Alquiler Iniciado";
|
||||
} else if (Cancelado == true && Habilitado == true) {
|
||||
data.Estado = "Nunca Empezo Esta Cancelado";
|
||||
}
|
||||
|
||||
if (Habilitado == false && Cancelado ==false){
|
||||
data.Estado = "Esta en Proceso";
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetHabitaciones(int habitaciones){
|
||||
data.Habitaciones = habitaciones;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetPiso(int piso){
|
||||
data.Piso = piso;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetLetra(string letra){
|
||||
data.Letra = letra;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetMesesAumento(int mesesAumento){
|
||||
data.MesesAumento = mesesAumento;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContratoPropiedadDtoBuilder SetMesesDuracion(int mesesDurationContrato) {
|
||||
data.MesesDuracion = mesesDurationContrato;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,42 @@ namespace AlquilaFacil.Controllers;
|
||||
[ApiController]
|
||||
public class ContratoController: ControllerBase {
|
||||
|
||||
[HttpGet("api/contratos/canon")]
|
||||
public ActionResult getCanons([FromHeader(Name="Auth")]string Auth, int id = 0) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false){
|
||||
validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) {
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
var list = RepositorioCanons.Singleton.ObtenerCanonsPorContrato(id);
|
||||
if (list == null) return BadRequest(new { message = "No hay contrato por esa id"});
|
||||
|
||||
var cont = RepositorioContratos.Singleton.ObtenerContratoPorId(id);
|
||||
if (cont == null) return BadRequest(new { message = ""});
|
||||
string divisa ="";
|
||||
if (cont.Iddivisa == 0) divisa = "AR$"; else if (cont.Iddivisa == 1) divisa = "US$";
|
||||
|
||||
List<CanonDto> d = new();
|
||||
|
||||
foreach (var i in list) {
|
||||
var c = new CanonDtoBuilder()
|
||||
.SetId(i.Id)
|
||||
.SetPago(i.Idrecibo==null?false:true)
|
||||
.SetDivisa(divisa==""?"Ugh esta mal cargado la divisa en el contrato":divisa)
|
||||
.SetMes(i.Fecha)
|
||||
.SetMesNum(int.Parse((i.Fecha.Month - cont.Fechainicio.Month).ToString()) + 1)
|
||||
.SetMonto(i.Monto)
|
||||
.Build();
|
||||
d.Add(c);
|
||||
}
|
||||
|
||||
return Ok(d);
|
||||
}
|
||||
|
||||
[HttpGet("api/contratos/propietario")]
|
||||
public IActionResult ObtenerContratosPorPropietario([FromHeader(Name="Auth")]string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -46,6 +82,39 @@ public class ContratoController: ControllerBase {
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
[HttpGet("api/contrato/propietario")]
|
||||
public IActionResult ObtenerContratoPorPropietarioPorId([FromHeader(Name="Auth")]string Auth, int id=0) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli==null) return Unauthorized();
|
||||
|
||||
if (id <= 0) return BadRequest(new { message = "No hay propiedades con id igual o menor a 0"});
|
||||
var i = RepositorioContratos.Singleton.ObtenerContratoPorId(id);
|
||||
if (i == null || i.DniinquilinoNavigation == null ||
|
||||
i.IdpropiedadNavigation == null || i.DnipropietarioNavigation == null)return BadRequest(new { message = "Fallo la query"});
|
||||
if (cli.Dni != i.Dnipropietario) return BadRequest(new { message = "No sos el propietario"});
|
||||
|
||||
var cont = new ContratoPropiedadDtoBuilder()
|
||||
.SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}")
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetId(i.Id)
|
||||
.SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}")
|
||||
.SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion)
|
||||
.SetFechaInicio(i.Fechainicio)
|
||||
.SetEstado(i.Habilitado, i.Cancelado)
|
||||
.SetHabitaciones(i.IdpropiedadNavigation.Canthabitaciones)
|
||||
.SetPiso(i.IdpropiedadNavigation.Piso??0)
|
||||
.SetLetra(i.IdpropiedadNavigation.Letra??"")
|
||||
.SetMesesAumento(i.MesesHastaAumento)
|
||||
.SetMesesDuracion(i.MesesDurationContrato)
|
||||
.Build();
|
||||
|
||||
return Ok(cont);
|
||||
}
|
||||
|
||||
[HttpGet("api/contratos/inquilino")]
|
||||
public IActionResult ObtenerContratosPorInquilino([FromHeader(Name="Auth")]string Auth) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
@@ -75,6 +144,39 @@ public class ContratoController: ControllerBase {
|
||||
}
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
[HttpGet("api/contrato/inquilino")]
|
||||
public IActionResult ObtenerContratoPorInquilinoPorId([FromHeader(Name="Auth")]string Auth, int id=0) {
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Inquilino");
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||
if (cli==null) return Unauthorized();
|
||||
|
||||
if (id <= 0) return BadRequest(new { message = "No hay propiedades con id igual o menor a 0"});
|
||||
var i = RepositorioContratos.Singleton.ObtenerContratoPorId(id);
|
||||
if (i == null || i.DniinquilinoNavigation == null ||
|
||||
i.IdpropiedadNavigation == null || i.DnipropietarioNavigation == null)return BadRequest(new { message = "Fallo la query"});
|
||||
if (cli.Dni != i.Dniinquilino) return BadRequest(new { message = "No sos el inquilino"});
|
||||
|
||||
var cont = new ContratoPropiedadDtoBuilder()
|
||||
.SetInquilino($"{i.DniinquilinoNavigation.Nombre} {i.DniinquilinoNavigation.Apellido}")
|
||||
.SetUbicacion(i.IdpropiedadNavigation.Ubicacion)
|
||||
.SetId(i.Id)
|
||||
.SetPropietario($"{i.DnipropietarioNavigation.Nombre} {i.DnipropietarioNavigation.Apellido}")
|
||||
.SetTipo(i.IdpropiedadNavigation.IdtipropiedadNavigation.Descripcion)
|
||||
.SetFechaInicio(i.Fechainicio)
|
||||
.SetEstado(i.Habilitado, i.Cancelado)
|
||||
.SetHabitaciones(i.IdpropiedadNavigation.Canthabitaciones)
|
||||
.SetPiso(i.IdpropiedadNavigation.Piso??0)
|
||||
.SetLetra(i.IdpropiedadNavigation.Letra??"")
|
||||
.SetMesesAumento(i.MesesHastaAumento)
|
||||
.SetMesesDuracion(i.MesesDurationContrato)
|
||||
.Build();
|
||||
|
||||
return Ok(cont);
|
||||
}
|
||||
|
||||
[HttpPost("api/contratos/precontrato")]
|
||||
public IActionResult IniciarPrecontrato([FromHeader(Name = "Auth")]string Auth, [FromBody] PrecontratoDto dto) {
|
||||
|
||||
Reference in New Issue
Block a user