Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2019
What would you like to do?
public class ValuesController : ControllerBase
private readonly ValuesRepository _repository;
public ValuesController(ValuesRepository repository)
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
// GET api/values
public async Task<List<Value>> Get()
return await _repository.GetAll();
// GET api/values/5
public async Task<ActionResult<Value>> Get(int id)
var response = await _repository.GetById(id);
if (response == null) { return NotFound(); }
return response;
// POST api/values
public async Task Post([FromBody] Value value)
await _repository.Insert(value);
// DELETE api/values/5
public async Task Delete(int id)
await _repository.DeleteById(id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment