public IActionResult UpdateBook(int id, [FromBody] PatchViewModel patchVm) { // TODO: Add support for more ops: remove, copy, move, test Book book = bookRepo.GetBookById(id); switch (patchVm.Path) { case "title": book.Title = patchVm.Value; break; case "date": book.Date = Convert.ToDateTime(patchVm.Value); break; case "author": book.Authors[0].Name = patchVm.Value; // TODO: manage author collection break; case "birthdate": book.Authors[0].Birthday = Convert.ToDateTime(patchVm.Value); break; default: return(BadRequest()); } bookRepo.Edit(book); return(Ok(book)); }
public IActionResult UpdateStory(string id, [FromBody] PatchViewModel patchVm) { // TODO: Add support for more ops: remove, copy, move, test StoriesModelForm story = storiesRepo.GetStoryById(id); switch (patchVm.Path) { case "title": story.StoryTitle = patchVm.Value; break; case "time": story.StoryTime = Convert.ToDateTime(patchVm.Value); break; case "poster": story.Poster.Name = patchVm.Value; // TODO: manage author collection break; case "topic": story.StoryTopic = patchVm.Value; break; case "text": story.StoryText = patchVm.Value; break; default: return(BadRequest()); } storiesRepo.Edit(story); return(Ok(story)); }