Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Updating the Data Model2:39 with James Churchill
Let’s make a couple of changes to the ComicBook model before we wrap up work on our models.
To follow along commiting your changes to this course, you'll need to fork the aspnet-comic-book-gallery repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork> cd aspnet-comic-book-gallery git checkout tags/v4.2 -b updating-the-data-model
For more information about creating data models using C#, see the excellent C# Objects Treehouse course.
The .NET String class contains a lot of different properties and methods that are indispensable when working with strings. Here’s the MSDN documentation on the String class.
CTRL+SHIFT+B- Build solution
Let's make a couple of changes to the comic book model
before we wrap up work on our models.
When displaying comic books on our website,
we need a string value that will uniquely identify the comic book for our users.
I'm going to name this property DisplayText.
It will return a string that is the combination of the SeriesTitle and
Let's also add a # right before the IssueNumber.
This property will be read only,
meaning that its value cannot be changed by directly setting this property.
We accomplish this by not defining a setter for our property.
Thinking ahead to the final design for
a couple of detail if you were going to display a cover image for each comic book.
To do this we'll need to know the file name for each image.
The comic book cover images that are included in our Website Design follow
the naming scheme series -title-issuenumber.jpg.
Let's add a read only cover image file name property
that contains our file naming logic.
Just like the displayed text property this property will only have a getter For
our return value will want to start with the series title property value.
Then, let's replace any spaces that the series title contains with hyphens.
To do this, we can use the string objects replace method.
The first parameter is the string that we want to replace.
And the second parameter is what to replace the first string with.
The Replace method returns a new string on which we can call the ToLower method
to force all of the string's characters to lowercase letters.
Next, add a hyphen and the IssuedNumber property value
followed by the string literal .jpg.
Excellent, both of these read only properties will come in handy
when we update our comic book detail view with our final design.
Let's build our project press Ctrl+Shift+B to build the solution.
We can monitor the progress of the build here in the output window and it's done.
One project succeeded and zero failed.
If you're using GitHub, let's commit our changes.
Enter a commit message of updated comic book
model and click the commit all button In the next video,
let's revisit how we're passing the comic book data from our controller to our view.
You need to sign up for Treehouse in order to download course files.Sign up