From the course: .NET Microservices for Azure Developers
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Creating a new pet - Azure Tutorial
From the course: .NET Microservices for Azure Developers
Creating a new pet
- [Instructor] The PetsController class is looking good, but it's missing the pet creation logic, so let's fix that. Let's add a new method that returns an IActionResult, and let's name it Create. And of course, we need to use the HttpPost attribute. Here, I can use a Pet object. However, I think it's better to have another model for pet creation, so let's create a new record named NewPet that has the Name, the Age, and the BreedId. So I can use newPet as a payload, and here, dbContext.Pets.AddAsync, and we need a way to transform the newPet object into a Pet object. So I'm going to implement that here, public Pet ToPet, so this is going to return a new Pet with the Age, the BreedId, and, of course, the Name, just like this. Let's close the braces, and now I'm ready to create a Pet variable and newPet ToPet, and I can use pet here. Then we need to save the changes, so await dbContext.SaveChangesAsync. And finally, we need to return the result. I can return Ok or I can use other…
Contents
-
-
-
-
Creating and cloning the repo1m 2s
-
(Locked)
Creating your first microservice using ASP.NET Core1m 54s
-
(Locked)
Creating and registering the DbContext for the microservice5m 49s
-
(Locked)
Creating the PetsController and returning the list of pets2m 36s
-
(Locked)
Obtaining a single pet in the PetsController1m 30s
-
(Locked)
Creating a new pet3m 21s
-
(Locked)
Challenge: Implementing BreedsController and validations1m 5s
-
(Locked)
Solution: Implementing BreedsController and validations1m 35s
-
-
-
-
-