Last active
October 1, 2017 01:34
-
-
Save tonysneed/44ebab19638a25d467fabd6239dedea7 to your computer and use it in GitHub Desktop.
This file contains 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
[Produces("application/json")] | |
[Route("api/Customer")] | |
public class CustomerController : Controller | |
{ | |
private readonly NorthwindSlimContext _context; | |
public CustomerController(NorthwindSlimContext context) | |
{ | |
_context = context; | |
} | |
// GET: api/Customer | |
[HttpGet] | |
public async Task<IActionResult> GetCustomers() | |
{ | |
var customers = await _context.Customers | |
.ToListAsync(); | |
return Ok(customers); | |
} | |
// GET: api/Customer/ALFKI | |
[HttpGet("{id}")] | |
public async Task<IActionResult> GetCustomer([FromRoute] string id) | |
{ | |
var customer = await _context.Customers.SingleOrDefaultAsync(m => m.CustomerId == id); | |
if (customer == null) | |
return NotFound(); | |
return Ok(customer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment