public async Task <IActionResult> Create(CreateAuthorCommand command) { try { if (ModelState.IsValid) { var appUser = await _userServices.GetUserAsync(User); var id = _author.CreateAuthor(command, appUser); return(RedirectToAction(nameof(View), new { id = id })); } } catch (Exception) { // Add a model-level error by using an empty string key ModelState.AddModelError( string.Empty, "An error occured saving author" ); _log.LogError("An error occured saving author"); } //If we got to here, something went wrong return(View(command)); }
public IActionResult CreateAuthor([FromBody] AuthorInputModel author) { if (!ModelState.IsValid) { return(StatusCode(412, author)); } var id = _authorService.CreateAuthor(author); return(CreatedAtRoute("GetAuthorById", new { id }, null)); }