-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCustomersController.cs
50 lines (44 loc) · 1.36 KB
/
CustomersController.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
using Customers.API.Models;
using Customers.API.Services;
using Microsoft.AspNetCore.Mvc;
namespace Customers.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class CustomersController : ControllerBase
{
private readonly ICustomerService _customerService;
public CustomersController(ICustomerService customerService)
{
_customerService = customerService;
}
// GET: api/customers
[HttpGet]
public async Task<IActionResult> Get()
{
var result = await _customerService.FindAllAsync();
return Ok(result);
}
// POST: api/customers
[HttpPost]
public async Task<IActionResult> Post([FromBody] Customer customer)
{
var result = await _customerService.InsertAsync(customer);
return Ok(result);
}
// PUT: api/customers
[HttpPut]
public async Task<IActionResult> Put([FromBody] Customer customer)
{
var result = await _customerService.UpdateAsync(customer);
return Ok(result);
}
// DELETE api/tasks?id=5
[HttpDelete]
public async Task<IActionResult> Delete([FromQuery] int id)
{
var result = await _customerService.DeleteAsync(id);
return Ok(result);
}
}
}