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 0:00 before we wrap up work on our models. 0:03 When displaying comic books on our website, 0:06 we need a string value that will uniquely identify the comic book for our users. 0:08 I'm going to name this property DisplayText. 0:13 It will return a string that is the combination of the SeriesTitle and 0:19 IssueNumber. 0:23 Let's also add a # right before the IssueNumber. 0:24 This property will be read only, 0:30 meaning that its value cannot be changed by directly setting this property. 0:32 We accomplish this by not defining a setter for our property. 0:36 Thinking ahead to the final design for 0:40 a couple of detail if you were going to display a cover image for each comic book. 0:42 To do this we'll need to know the file name for each image. 0:48 The comic book cover images that are included in our Website Design follow 0:51 the naming scheme series -title-issuenumber.jpg. 0:56 Let's add a read only cover image file name property 1:04 that contains our file naming logic. 1:08 Just like the displayed text property this property will only have a getter For 1:11 our return value will want to start with the series title property value. 1:16 Then, let's replace any spaces that the series title contains with hyphens. 1:21 To do this, we can use the string objects replace method. 1:27 The first parameter is the string that we want to replace. 1:31 And the second parameter is what to replace the first string with. 1:35 The Replace method returns a new string on which we can call the ToLower method 1:39 to force all of the string's characters to lowercase letters. 1:44 Next, add a hyphen and the IssuedNumber property value 1:48 followed by the string literal .jpg. 1:54 Excellent, both of these read only properties will come in handy 1:59 when we update our comic book detail view with our final design. 2:03 Let's build our project press Ctrl+Shift+B to build the solution. 2:07 We can monitor the progress of the build here in the output window and it's done. 2:11 One project succeeded and zero failed. 2:17 If you're using GitHub, let's commit our changes. 2:20 Enter a commit message of updated comic book 2:24 model and click the commit all button In the next video, 2:29 let's revisit how we're passing the comic book data from our controller to our view. 2:34
You need to sign up for Treehouse in order to download course files.Sign up