Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[ApiController]
[Route("api/[controller]")]
public class CountriesController: ControllerBase
{
private readonly ApplicationDbContext context;
public CountriesController(ApplicationDbContext context)
{
this.context = context;
}
[HttpGet]
public async Task<ActionResult<List<Country>>> Get()
{
return await context.Countries.OrderBy(x => x.Name).ToListAsync();
}
[HttpGet("{countryId}/states")]
public async Task<List<State>> GetStates(int countryId)
{
return await context.States.Where(x => x.CountryId == countryId)
.OrderBy(x => x.Name).ToListAsync();
}
}
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.