I have a controller which gets data from a database but i want to have multiple methods [Actions] for the same GetAll Method based on different key.
Example
consider this DB
can i have a controller with different GetAll method based on CountryID, AddressID, DepartmentID like this
[ApiController]
[Route("api/Users")]
public class UsersController : ControllerBase
{
//Without a key
[HttpGet]
public IEnumerable<User> GetAll()
{
return repository.GetAll();
}
[HttpGet("{addressId}")]
public async IEnumerable<User> GetAll([FromRoute]string addressId)
{
User user= repository.GetAll(addressId);
}
[HttpGet("{CountryID}")]
public async IEnumerable<User> GetAll([FromRoute]string CountryID)
{
User user= repository.GetAll(CountryID);
}
[HttpGet("{DepartmentID }")]
public async IEnumerable<User> GetAll([FromRoute]string DepartmentID )
{
User user= repository.GetAll(DepartmentID );
}
}
and if i can how can i call this different method from the http request.
thanks in advance
