| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using Microsoft.AspNetCore.Mvc; |
| | 4 | | using SampleDotNetCore2RestStub.Models; |
| | 5 | | using SampleDotNetCore2RestStub.Repositories; |
| | 6 | |
|
| | 7 | | namespace SampleDotNetCore2RestStub.Controllers |
| | 8 | | { |
| | 9 | | public class PersonController : Controller |
| | 10 | | { |
| | 11 | | private readonly IPersonRepository _personRepository; |
| | 12 | |
|
| 1 | 13 | | public PersonController(IPersonRepository personRepository) |
| | 14 | | { |
| 1 | 15 | | _personRepository = personRepository; |
| | 16 | | } |
| | 17 | |
|
| | 18 | | [HttpGet("person/get/{id}")] |
| | 19 | | public Person GetPerson(int id) |
| | 20 | | { |
| 1 | 21 | | return _personRepository.GetById(id); |
| | 22 | | } |
| | 23 | |
|
| | 24 | | [HttpGet("person/remove")] |
| | 25 | | public string RemovePerson() |
| | 26 | | { |
| 0 | 27 | | _personRepository.Remove(); |
| 0 | 28 | | return "Last person remove. Total count: " + _personRepository.GetCount(); |
| | 29 | | } |
| | 30 | |
|
| | 31 | | [HttpGet("person/all")] |
| | 32 | | public List<Person> GetPersons() |
| | 33 | | { |
| 1 | 34 | | return _personRepository.GetAll(); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | [HttpPost("person/save")] |
| | 38 | | public string AddPerson([FromBody]Person person) |
| | 39 | | { |
| 0 | 40 | | return _personRepository.Save(person); |
| | 41 | | } |
| | 42 | | } |
| | 43 | | } |