Implementing BaseApiController

The next thing to do is to derive the QuizController, QuestionController, AnswerController, and ResultController from this BaseApiController class, so they can inherit the shared properties and get rid of a lot of duplicate code; let's start with the QuizController.

Open the QuizController.cs file and perform the following changes (updated lines are highlighted):

[...]namespace TestMakerFreeWebApp.Controllers{    public class QuizController : BaseApiController    {        #region Constructor        public QuizController(ApplicationDbContext context)            : base(context) { }        #endregion[...]

As we can see, we removed the following:

  • The [Route("api/[controller]")] attribute, since it's already present in the BaseApiController; all the ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.