12.0: Add Star Option
Add isStarred
Property to Database
isStarred
Property to DatabaseLet's add an option to star a note. This is an example of how to make changes after you've completed the first version of something. It's a good idea to branch off and do this on a separate branch.
First, we need to update our database to have a property of wether or not a note is starred.
Go to ElevenNote.Data -> Note.cs
Add the following property between the
Content
andCreatedUtc
propertiesCTRL .
to bring in the using statementIn order for the database to be updated with this new column, we need to:
Update the NoteListItem
Model
NoteListItem
ModelWe'll want a clickable star on the page that shows all of our notes. The model for that view is NoteListItem
Go to ElevenNote.Models -> NoteListItem.cs and add the
IsStarred
property between theTitle
andCreatedUtc
The
UIHint
will link up to a view we make later
Update NoteService.cs
NoteService.cs
We'll need the service to know about the star as well???
Add the
IsStarred
option inIEnumerable<NoteListItem>
.
Add Star to Index View
We need to add a column and column name for the isStarred
property in our table that displays the list of notes.
Open ElevenNote.Web -> Views -> Note -> Index.cshtml
Add the
DisplayNameFor
forIsStarred
Add the
DisplayFor
forIsStarred
Now, we need some JavaScript to make the star functionality work
Add this code to the very end of
Index.cshtml
, after</table>
:
Add the Starred Display Template
Similar to the DateTime display changes we made, we'll make a view specifically for the star. Notice that the name of this view, Starred
, is the same as the UIHint
from the NoteListItem
model.
Right click on the ElevenNote.Web -> Views -> Shared -> Display Templates folder and select Add -> View
Name it
Starred
and fill it out like this:Add this code:
Next, we'll do more setup to get the star function working.
Last updated