Exercise: Finishing the Comic Book Artists Controller4:04 with James Churchill
Now that we have the ability for our users to create, read, update, and delete comic books, the top level "Comic Books" section of our web app is almost complete. That's your next exercise: finishing the pages that allow users to add and remove comic book artists.
To follow along committing your changes to this course, you'll need to fork the dotnet-comic-book-library-manager repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork> cd dotnet-comic-book-library-manager git checkout tags/v2.7 -b exercise-finishing-the-comic-book-artists-controller
To finish the exercise, complete the following tasks:
- Add a private field for the database context and a default constructor to initialize the private field.
- Override the
Disposemethod and handle disposing the database context.
Add GET Action Method
- Write a query that retrieves a comic book with the
Seriesnavigation property eagerly loaded.
- Pass the context into the view model
Add POST Action Method
- Handle adding the comic book artist entity to the database.
- Prepare the view model for the view by writing a query to retrieve the comic book with the
Seriesnavigation property eagerly loaded and pass the context into the view model's
Hint: When you instantiate an instance of the ComicBookArtist entity to add to the database context, you'll need to set its
ComicBookId property value. You can get the ID of the comic book that we're adding an artist to using the view model's
Delete GET Action Method
- Write a query to retrieve the comic book artist with the
Rolenavigation properties eagerly loaded.
Delete POST Action Method
- Handle deleting the comic book artist entity from the database.
- Write a query that checks for the existence of a comic book artist entity that has the same
RoleIdproperty values as the passed entity.
- Add a parameter for the database context instance.
- Write a query to retrieve a list of artists.
- Write a query to retrieve a list of roles.
- Add a DbSet property for ComicBookArtist entities.
You need to sign up for Treehouse in order to download course files.Sign up