Writing controllers and routes
We are now in the section where we will be writing controllers that process HTTP requests from the client application. We are also going to write routes that redirect an HTTP request to its respective controller.
These will be two simple controllers, but we will refactor them in the next chapter, Chapter 6, Diving into CQRS.
TourPackagesController
We will be creating the controller for TourPackages
that will handle and process any requests that will retrieve and update TourPackages
table in the database:
- Now go back to the
Travel.WebApi
project and createTourPackagesController.cs
inside of theControllers
directory and write the following code:using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; using Travel.Data.Contexts; using Travel.Domain.Entities;
The code imports the preceding
namespaces
, which are needed in this controller. - Next, write the
controller
class:namespace Travel.WebApi...