public async Task <IActionResult> CreateLibrary([FromBody] LibraryView library, CancellationToken token) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var request = new AddLibraryRequest(library.Map()); await _commandProcessor.SendAsync(request, cancellationToken : token); var renderResult = _libraryRenderer.Render(request.Result); return(new CreatedResult(renderResult.Links.Self(), renderResult)); }
public async Task <IActionResult> UpdateLibrary(int libraryId, [FromBody] LibraryView library, CancellationToken token = default(CancellationToken)) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var request = new UpdateLibraryRequest(libraryId, library.Map()); await _commandProcessor.SendAsync(request, cancellationToken : token); var renderResult = _libraryRenderer.Render(request.Result.Library); if (request.Result.HasAddedNew) { return(new CreatedResult(renderResult.Links.Self(), renderResult)); } else { return(new OkObjectResult(renderResult)); } }