Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.