public async Task <IActionResult> AddAuthor([FromBody] AuthorResource authorResource) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var author = mapper.Map <AuthorResource, Author>(authorResource); author.LastUpdate = DateTime.Now; authorsRepository.AddAuthorAsync(author); await unitOfWork.CompleteAsync(); var newAuthor = await authorsRepository.GetAuthorByIdAsync(author.Id); return(Ok(mapper.Map <Author, AuthorResource>(newAuthor))); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }