December 2018
Beginner to intermediate
668 pages
15h 30m
English
Open the Part3 solution, and expand the NorthwindService project.
In the Controllers folder, right-click and choose Add | New Item..., select Web API Controller Class, name it as CategoriesController.cs, and modify it to have two HttpGet methods that use the Northwind database context to retrieve all categories, or a single category using its ID, as shown in the following code:
using Microsoft.AspNetCore.Mvc;using Packt.CS7;using System.Collections.Generic;using System.Linq;namespace NorthwindService.Controllers{ [Route("api/[controller]")] public class CategoriesController : Controller { private readonly Northwind db; public CategoriesController(Northwind db) { this.db = db; } // GET: api/categories [HttpGet] ...Read now
Unlock full access