por hoy todo
This commit is contained in:
46
Aspnet/Controllers/DefectoController.cs
Normal file
46
Aspnet/Controllers/DefectoController.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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);
|
||||||
|
return Ok(l);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Entidades/Dto/AltaDefectoDto.cs
Normal file
8
Entidades/Dto/AltaDefectoDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Entidades.Dto;
|
||||||
|
public class AltaDefectoDto {
|
||||||
|
public string Descripcion { get; set; } ="";
|
||||||
|
public Decimal Costo { get; set; }
|
||||||
|
public ulong Pagainquilino { get; set; }
|
||||||
|
public int Iddivisa { get; set; }
|
||||||
|
public long Idcontrato { get; set; }
|
||||||
|
}
|
||||||
10
Entidades/Dto/DefectoDto.cs
Normal file
10
Entidades/Dto/DefectoDto.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Entidades.Dto;
|
||||||
|
public class DefectoDto {
|
||||||
|
public long Id { get; set;}
|
||||||
|
public string Descripcion { get; set;} ="";
|
||||||
|
public Decimal Costo { get; set;}
|
||||||
|
public int Idestado { get; set;}
|
||||||
|
public long Idcontrato { get; set;}
|
||||||
|
public bool Pagainquilino { get; set;}
|
||||||
|
public int Iddivisa { get; set;}
|
||||||
|
}
|
||||||
12
Modelo/RepositorioDefectos.cs
Normal file
12
Modelo/RepositorioDefectos.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using Entidades;
|
||||||
|
|
||||||
|
namespace Modelo;
|
||||||
|
|
||||||
|
public class RepositorioDefectos: RepositorioBase<RepositorioDefectos> {
|
||||||
|
public IQueryable<Defecto> ObtenerDefectosPorIdContrato(long idcontrato){
|
||||||
|
var con = Context;
|
||||||
|
|
||||||
|
var l = con.Defectos.Where(x=>x.Idcontrato == idcontrato);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user