12.2: Star API
Add an API for the IsStarred option
IsStarred optionnamespace ElevenNote.Web.Controllers.WebAPI { [Authorize] [RoutePrefix("api/Note")] public class NoteController : ApiController { private bool SetStarState(int noteId, bool newState) { // Create the service var userId = Guid.Parse(User.Identity.GetUserId()); var service = new NoteService(userId); // Get the note var detail = service.GetNoteById(noteId); // Create the NoteEdit model instance with the new star state var updatedNote = new NoteEdit { NoteId = detail.NoteId, Title = detail.Title, Content = detail.Content, IsStarred = newState }; // Return a value indicating whether the update succeeded return service.UpdateNote(updatedNote); } [Route("{id}/Star")] [HttpPut] public bool ToggleStarOn(int id) => SetStarState(id, true); [Route("{id}/Star")] [HttpDelete] public bool ToggleStarOff(int id) => SetStarState(id, false); } }
Add IsStarred Property to NoteEdit Model
IsStarred Property to NoteEdit ModelAdd IsStarred in the UpdateNote method
IsStarred in the UpdateNote methodLast updated