commit casi todo listo
This commit is contained in:
@@ -74,11 +74,22 @@ public class ContratoController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("api/contratos/crearcanons")] //WIP
|
[HttpPost("api/contratos/crearcanons")] //WIP
|
||||||
public IActionResult crearCanons([FromHeader(Name="Auth")]string Auth){
|
public IActionResult crearCanons([FromHeader(Name="Auth")]string Auth, CrearCanonsDto dto){
|
||||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Propietario");
|
||||||
if (validacion1 == false)return Unauthorized();
|
if (validacion1 == false)return Unauthorized();
|
||||||
|
Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth);
|
||||||
|
if (cli == null) return Unauthorized();
|
||||||
|
|
||||||
|
if (dto.aumento <=Decimal.Zero || dto.idcontrato <=0) return BadRequest(new { message ="estan mal cargados los datos"});
|
||||||
|
|
||||||
|
Contrato? cont = RepositorioContratos.Singleton.ObtenerContratoPorId(dto.idcontrato);
|
||||||
|
if (cont == null) return BadRequest(new { message = "no hay un contrato por esa id"});
|
||||||
|
if (cli.Dni != cont.Dnipropietario) return BadRequest(new {message = "No sos el propietario o intenta volviendote a logear"});
|
||||||
|
|
||||||
|
var ret = RepositorioCanons.Singleton.CrearCanons(dto.aumento, dto.idcontrato);
|
||||||
|
return ret ?
|
||||||
|
Ok(new { message = "Se crearon los canons correctamente"}):BadRequest(new { message = "No se pudo guardar"});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("api/contratos/canon")]
|
[HttpGet("api/contratos/canon")]
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Entidades.Dto;
|
||||||
|
|
||||||
|
public class CrearCanonsDto {
|
||||||
|
public long idcontrato{ get; set; }
|
||||||
|
public decimal aumento{ get; set; }
|
||||||
|
}
|
||||||
@@ -42,4 +42,28 @@ public class RepositorioCanons: RepositorioBase<RepositorioCanons> {
|
|||||||
|
|
||||||
return Guardar(con);
|
return Guardar(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CrearCanons(decimal aumento, long idcontrato) { //WIP
|
||||||
|
var con = Context;
|
||||||
|
|
||||||
|
aumento+=1;
|
||||||
|
|
||||||
|
var cont = con.Contratos.Include(x=>x.Idcanons).FirstOrDefault(x=>x.Id == idcontrato);
|
||||||
|
if (cont == null) return false;
|
||||||
|
|
||||||
|
int exist = cont.Idcanons.Count();
|
||||||
|
if (exist+cont.MesesHastaAumento >= cont.MesesDurationContrato){
|
||||||
|
exist = cont.MesesDurationContrato-exist;
|
||||||
|
} else{
|
||||||
|
exist = cont.MesesHastaAumento;
|
||||||
|
}
|
||||||
|
|
||||||
|
cont.Monto = cont.Monto * aumento;
|
||||||
|
|
||||||
|
for (int i = 0; i < exist; i++){
|
||||||
|
Canon c = new Canon{
|
||||||
|
Fecha
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user