August 2017
Intermediate to advanced
330 pages
7h 26m
English
Add a new web API controller class in the Controllers folder, naming it as DepartmentController and add the following code to perform CRUD operations using HTTP verbs:
[Route("api/[controller]")] public class DepartmentController : Controller { private readonly IDepartmentRepository _deptrepo; public DepartmentController(IDepartmentRepository deptrepo) { _deptrepo = deptrepo; } // GET: api/values [HttpGet] public IActionResult Get() { var results = _deptrepo.GetDepartments(); return Ok(results); } // GET api/values/5 [HttpGet("{id}")] public IActionResult Get(int id) { if (!_deptrepo.DepartmentExists(id)) { return NotFound(); } var dept = _deptrepo.GetDepartment(id); return Ok(dept); } // POST api/values ...Read now
Unlock full access