Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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.
Follow Along
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
Exercise
To finish the exercise, complete the following tasks:
ComicBookLibraryManagerWebApp/Controllers/ComicBookArtistsController.cs File
- Add a private field for the database context and a default constructor to initialize the private field.
- Override the
Dispose
method and handle disposing the database context.
Add
GET Action Method
- Write a query that retrieves a comic book with the
Series
navigation property eagerly loaded. - Pass the context into the view model
Init
method call.
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
Series
navigation property eagerly loaded and pass the context into the view model'sInit
method.
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 ComicBookId
property.
Delete
GET Action Method
- Write a query to retrieve the comic book artist with the
ComicBook
,ComicBook.Series
,Artist
, andRole
navigation properties eagerly loaded.
Delete
POST Action Method
- Handle deleting the comic book artist entity from the database.
ValidateComicBookArtist
Method
- Write a query that checks for the existence of a comic book artist entity that has the same
ComicBookId
,AritstId
, andRoleId
property values as the passed entity.
ComicBookLibraryManagerWebApp/ViewModels/ComicBookArtistsAddViewModel.cs File
Init
Method
- 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.
ComicBookShared/Data/Context.cs File
- Add a DbSet property for ComicBookArtist entities.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up