Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tonysneed
Last active October 1, 2017 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysneed/44ebab19638a25d467fabd6239dedea7 to your computer and use it in GitHub Desktop.
Save tonysneed/44ebab19638a25d467fabd6239dedea7 to your computer and use it in GitHub Desktop.
[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