December 2019
Intermediate to advanced
598 pages
12h 21m
English
Let's implement deleting a question. This follows a similar pattern to the previous methods:
[HttpDelete("{questionId}")]public ActionResult DeleteQuestion(int questionId){ var question = _dataRepository.GetQuestion(questionId); if (question == null) { return NotFound(); } _dataRepository.DeleteQuestion(questionId); return NoContent();}
We use the HttpDelete attribute to tell ASP.NET Core that this method handles HTTP DELETE requests. The method expects the question ID to be included at the end of the path.
The method checks the question that exists before deleting it and returns an HTTP 404 status code ...
Read now
Unlock full access