Skip to content

Instantly share code, notes, and snippets.

@johanvergeer
Created May 19, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanvergeer/b515c0ff18a6bd695080f0c01190508d to your computer and use it in GitHub Desktop.
Save johanvergeer/b515c0ff18a6bd695080f0c01190508d to your computer and use it in GitHub Desktop.
Person API Controller
[Route("api/[controller]")]
[ApiController]
public class PersonController : Controller
{
private readonly IPersonRepository _repository;
public PersonController(IPersonRepository _repository)
{
this._repository = _repository;
}
[HttpGet]
public ActionResult<IEnumerable<Person>> Get()
{
return this._repository.FindAll().ToList();
}
public IActionResult Post(Person person)
{
if (!person.IsValid)
{
return BadRequest("Person has invalid state");
}
this._repository.Add(person);
return Ok("Person added");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment