public async Task <ActionResult> UpdateChapter( [FromRoute] ChapterReference reference, [FromBody] UpdateChapterRequest request, CancellationToken cancellationToken) { var command = new UpdateChapterCommand(reference.SagaId, reference.ChapterId, request.Content); try { await _sender.Send(command, cancellationToken); } catch (ChapterNotFoundException e) { return(NotFound(e.Message)); } return(NoContent()); }
public async Task <IActionResult> UpdateChapter(int libraryId, int bookId, int chapterNumber, [FromBody] ChapterView chapter, CancellationToken token = default(CancellationToken)) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var request = new UpdateChapterRequest(libraryId, bookId, chapterNumber, chapter.Map()); await _commandProcessor.SendAsync(request, cancellationToken : token); var renderResult = _chapterRenderer.Render(request.Result.Chapter, libraryId, bookId); if (request.Result.HasAddedNew) { return(new CreatedResult(renderResult.Links.Self(), renderResult)); } return(new OkObjectResult(renderResult)); }