public Task <IActionResult> Update(string entryId, EntryStoryUpdateModel model) => RunEntryAsync(entryId, Permission.Write, async entry => { string userId = HttpContext.User.FindUserId(); Story story = null; StoryChapter chapter = null; if (model.StoryId != null) { story = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Stories, userId) .Where(s => s.Id == model.StoryId) .Include(s => s.Chapters) .FirstOrDefaultAsync(); if (story == null) { model.StoryId = null; model.ChapterId = null; } else if (story.UserId != entry.UserId) { return(BadRequest()); } } if (model.ChapterId != null) { chapter = story.Chapters.FirstOrDefault(c => c.Id == model.ChapterId); if (chapter == null) { story = null; } } if (story == null) { entry.Story = null; entry.Chapter = null; } else if (chapter == null) { entry.Story = story; entry.Chapter = null; } else { entry.Story = null; entry.Chapter = chapter; } db.Entries.Update(entry); await db.SaveChangesAsync(); return(NoContent()); });
protected async void EntrySelected(TimelineEntryModel entry) { var model = new EntryStoryUpdateModel(Model.Id); if (entrySelectionChapter != null) { model.ChapterId = entrySelectionChapter.Id; } entrySelectionChapter = null; await Api.UpdateEntryStoryAsync(entry.Id, model); await EventDispatcher.PublishAsync(new StoryEntriesChanged(model.StoryId, model.ChapterId, entry.Id)); }