August 2017
Intermediate to advanced
330 pages
7h 26m
English
Right-click on the Controllers folder to add the Web API Controller class, and name it as ProductController. Copy the following piece of code to perform CRUD operations on the Product table:
public class ProductController : Controller { private readonly IProductRepository _productRepository; public ProductController(IProductRepository productRepository) { _productRepository = productRepository; } // GET: api/values [HttpGet] public IActionResult Get() { var prodlist = _productRepository.GetProducts(); var results = Mapper.Map<IEnumerable<ProductDTO>>(prodlist); return Ok(results); } // GET api/values/5 [HttpGet("{id}")] public IActionResult Get(int id) { if (!_productRepository.ProductExists(id)) ...