Updating the QuizController

Last but not least, we need to make some changes to the QuizController to make it use the ApplicationDbContext to retrieve data instead of those Dummy Data Provider strategies we implemented back in Chapter 2, Backend with .NET Core.

In order to do that, the first thing we need to do is to find an efficient way to map each Quiz entity to a corresponding QuizViewModel object, as our new Data Provider won’t generate them anymore. We can achieve such a result in a number of ways, including the following:

  • Adding a Helper Method, such as GetQuizViewModel(Quiz quiz), thus handling the mapping manually with a few lines of code
  • Adding a Constructor Method to the QuizViewModel itself, such as QuizViewModel(Quiz quiz)

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.