Created
April 14, 2019 23:15
-
-
Save adlerpagliarini/0c3bd584a9d26bd7303d2f86db39f726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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