Person Controller
Person Controller
[Route("api/[controller]")]
[ApiController]
[HttpGet]
public ActionResult<List<object>> GetPerson()
{
var persons = _personService.GetPerson();
return Ok(result);
}
[HttpGet("{id}")]
public ActionResult<object> GetPersonById(int id)
{
var person = _personService.GetPersonById(id);
if (person == null)
{
return NotFound();
}
return Ok(result);
}
//El POST
[HttpPost]
public ActionResult<Person> AddPerson(Person person)
{
return
CreatedAtAction(
nameof(GetPerson), new
{
id = newProducto.Id
},
newProducto);
//El PUT
//Permite actualizar el registro
[HttpPut]
public IActionResult UpdatePerson(Person person)
{
if (!_personService.UpdatePerson(person))
{
return NotFound(
new
{
elmensaje = "person not found"
}
);
}
return NoContent();
}
//El Delete
//Borra un registro
[HttpDelete]
public IActionResult DeletePerson(int id)
{
if (!_personService.DeletePerson(id))
{
return NotFound(
new
{
elmensaje = "person not found"
}
);
}
return NoContent();
}
}
}