60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using AlquilaFacil.Builder;
|
|
using Entidades;
|
|
using Entidades.Dto;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Modelo;
|
|
|
|
namespace AlquilaFacil.Controllers;
|
|
|
|
[ApiController]
|
|
public class DefectoController: ControllerBase {
|
|
|
|
[HttpGet("api/defectos")]
|
|
public IActionResult ObtenerDefectosEnContrato([FromHeader(Name = "Auth")] string Auth, long Idcontrato = 0) {
|
|
if (Idcontrato <= 0) return BadRequest( new { message = "La id de contrato no puede ser menor o igual a 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();
|
|
}
|
|
}
|
|
|
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
|
if (cli == null) return Unauthorized();
|
|
|
|
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(Idcontrato);
|
|
if (cont == null) return BadRequest(new { message = "No hay contrato por esa id"});
|
|
|
|
if (cont.Dniinquilino != cli.Dni && cont.Dnipropietario != cli.Dni) return BadRequest(new { message = "no deberias tener acceso a esto"});
|
|
|
|
var l = RepositorioDefectos.Singleton.ObtenerDefectosPorIdContrato(Idcontrato);
|
|
List<DefectoDto> ll = new();
|
|
foreach (var i in l){
|
|
var n = new DefectoDtoBuilder()
|
|
.SetId(i.Id)
|
|
.SetDesc(i.Descripcion)
|
|
.SetCosto(i.Costo)
|
|
.SetEstado(i.IdestadoNavigation.Descipcion)
|
|
.SetIdContrato(i.Idcontrato??0)
|
|
.SetPagaInquilino(i.Pagainquilino)
|
|
.SetDivisa(i.IddivisaNavigation.Signo)
|
|
.Build();
|
|
ll.Add(n);
|
|
}
|
|
return Ok(ll);
|
|
}
|
|
|
|
[HttpPost("api/defecto")] // WIP tengo que hablar con mi madre
|
|
public IActionResult AltaDefecto([FromHeader(Name = "Auth")] string Auth, AltaDefectoDto data) {
|
|
|
|
}
|
|
|
|
[HttpPut("api/defecto/marcarpago")] // WIP Prerequisito tener altadefecto
|
|
public IActionResult MarcarPago([FromHeader(Name = "Auth")] string Auth, long iddefecto = 0) {
|
|
|
|
}
|
|
}
|