-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPesoIdealController.cs
40 lines (35 loc) · 1.04 KB
/
PesoIdealController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Microsoft.AspNetCore.Mvc;
namespace PesoIdealAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PesoIdealController : ControllerBase
{
// POST api/pesoideal
[HttpPost]
public ActionResult<double> CalcularPesoIdeal([FromBody] PesoRequest request)
{
if (request == null)
{
return BadRequest("Datos inválidos.");
}
double pesoIdeal = 0;
// Fórmulas simplificadas de cálculo de peso ideal
if (request.Sexo.ToLower() == "masculino")
{
pesoIdeal = 50 + 0.91 * (request.Estatura - 152);
}
else if (request.Sexo.ToLower() == "femenino")
{
pesoIdeal = 45.5 + 0.91 * (request.Estatura - 152);
}
return Ok(pesoIdeal);
}
}
public class PesoRequest
{
public string Sexo { get; set; }
public int Edad { get; set; }
public double Estatura { get; set; }
}
}