12.2: Star API
Add an API for the IsStarred
option
IsStarred
optionIn this section, we will add an API specifically for our star functionality. Please note: This is different from the API we will use later for working with other presentation tiers
In the ElevenNote.Web -> Controllers folder, add a new folder called WebAPI
Add a Controller (Web API 2 Controller - Empty) named NoteController
This controller is completely different from the MVC
NoteController
Add this code:
CTRL .
to bring in the using statementsIgnore the error on
IsStarred
for now, we'll fix that later
Add IsStarred
Property to NoteEdit
Model
IsStarred
Property to NoteEdit
ModelGo to ElevenNote.Models -> NoteEdit.cs
Add the
IsStarred
property.Go back to ElevenNote.Web -> Controllers -> WebAPI -> NoteController.cs
Notice that the error is gone
Run the app and test out the stars
If you refresh the page do the notes stay starred?
Add IsStarred
in the UpdateNote
method
IsStarred
in the UpdateNote
methodWe need to save the star status and update this info in the database
Go to ElevenNote.Services -> NoteService.cs
Scroll down to the
UpdateNote
method and add the line starting withentity.IsStarred...
Run the app and test out the star
Let's change the
Display(Name)
in the list view - ElevenNote.Models -> NoteListItem.csTo see the
IsStarred
property change, open up yourdbo.Note
while the app is running. Refresh the table once you've selected/deselected the star.If you've done this on a separate branch, now would probably be a good time to merge this into the other branch.
Next, we'll create a different API. This will be the API used for connecting to other presentation tiers in your application.
Last updated