We can now add an additional API endpoint to the Features/Products/Controller.cs file. The controller action definition looks like this:
[HttpPost, Authorize(Roles = "Admin")]public async Task<IActionResult> Create([FromBody] CreateProductViewModel model){ ...}
This endpoint will only accept HTTP POST requests from authenticated users who belong to the Admin role. Remembering that our custom typeahead control allows users to enter any arbitrary string value, we first need to check whether what they entered for the brand and operating system already exist in the database or not. We do this as follows:
var brand = await _db.Brands.FirstOrDefaultAsync(x => x.Name == model.Brand);if (brand == null) brand = new Brand ...