-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathPersonController.cs
67 lines (60 loc) · 1.89 KB
/
PersonController.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Blazorcrud.Server.Authorization;
using Blazorcrud.Server.Models;
using Blazorcrud.Shared.Models;
using Microsoft.AspNetCore.Mvc;
namespace Blazorcrud.Server.Controllers
{
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class PersonController : ControllerBase
{
private readonly IPersonRepository _personRepository;
public PersonController(IPersonRepository personRepository)
{
_personRepository = personRepository;
}
/// <summary>
/// Returns a list of paginated people with a default page size of 5.
/// </summary>
[AllowAnonymous]
[HttpGet]
public ActionResult GetPeople([FromQuery] string? name, int page)
{
return Ok(_personRepository.GetPeople(name, page));
}
/// <summary>
/// Gets a specific person by Id.
/// </summary>
[AllowAnonymous]
[HttpGet("{id}")]
public async Task<ActionResult> GetPerson(int id)
{
return Ok(await _personRepository.GetPerson(id));
}
/// <summary>
/// Creates a person with child addresses.
/// </summary>
[HttpPost]
public async Task<ActionResult> AddPerson(Person person)
{
return Ok(await _personRepository.AddPerson(person));
}
/// <summary>
/// Updates a person with a specific Id.
/// </summary>
[HttpPut]
public async Task<ActionResult> UpdatePerson(Person person)
{
return Ok(await _personRepository.UpdatePerson(person));
}
/// <summary>
/// Deletes a person with a specific Id.
/// </summary>
[HttpDelete("{id}")]
public async Task<ActionResult> DeletePerson(int id)
{
return Ok(await _personRepository.DeletePerson(id));
}
}
}