Created
May 19, 2019 14:09
-
-
Save johanvergeer/b515c0ff18a6bd695080f0c01190508d to your computer and use it in GitHub Desktop.
Person API Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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