public async Task <IActionResult> AddAuthor([FromBody] Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _authorsService.AddAuthorAsync(author); return(Ok(result)); }
public async Task <ActionResult <Author> > AddAuthor([FromBody] Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Author added = await authorsService.AddAuthorAsync(author); return(Created($"/{added.Id}", added)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }