Modifying the HomeController

The last thing we need to do before we can run our application is to modify the HomeController class to work with the IWorkItemService:

  1. Modify the constructor and the Index action as follows:
private readonly IWorkItemService _workItemService; 
 
public HomeController(IWorkItemService workItemService) 
{ 
    _workItemService = workItemService; 
             
} 
 
public IActionResult Index() 
{ 
    var workItems = _workItemService.GetAllWorkItems(); 
    return View(workItems); 
} 
  1. We are getting all the work items in the MongoDB database and passing them to the view for the model to work with.
Make sure that you have started the MongoDB server by using the mongod -dbpath <path> command format, as explained earlier in the chapter.
  1. When you are ...

Get C# 7 and .NET Core 2.0 Blueprints 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.