Implementing CRUD controllers
In this section, we will implement the controllers to handle the HTTP requests, which are the GET
, POST
, PUT
, and DELETE
operations that are used to retrieve, create, update, and delete data, respectively.
Creating the controller
If you have installed the dotnet aspnet-codegenerator
tool following Chapter 2, you can use the following command to create a controller with the specific DbContext
. Do not forget to install the Microsoft.VisualStudio.Web.CodeGeneration.Design
NuGet package, which is required by the dotnet
aspnet-codegenerator
tool:
# Install the tool if you have not installed it yet.#dotnet tool install -g dotnet-aspnet-codegenerator dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design dotnet-aspnet-codegenerator controller -name InvoicesController -api -outDir Controllers ––model Invoice ––dataContext InvoiceDbContext -async -actions
The preceding command has some parameters as shown here...