Skip to content

Instantly share code, notes, and snippets.

@adlerpagliarini
Created April 14, 2019 23:15
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 adlerpagliarini/0c3bd584a9d26bd7303d2f86db39f726 to your computer and use it in GitHub Desktop.
Save adlerpagliarini/0c3bd584a9d26bd7303d2f86db39f726 to your computer and use it in GitHub Desktop.
[Produces("application/json")]
[Route("api/[controller]")]
public class DeveloperController : ControllerBase
{
private readonly DatabaseContext _context;
public DeveloperController(DatabaseContext context)
{
_context = context;
}
[HttpPost]
public async Task<IActionResult> CreateUser([FromBody] Developer developer)
{
_context.Developer.Add(developer);
await _context.SaveChangesAsync();
return CreatedAtAction("Get", new { id = developer.Id }, developer);
}
[HttpGet]
[Route("{id}")]
public async Task<ActionResult<Developer>> Get(int id)
{
var developer = await _context.Developer.FindAsync(id);
if (developer == null) return NotFound();
return developer;
}
[HttpGet]
public IEnumerable<Developer> Get() => _context.Developer.AsQueryable();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment