public IActionResult CreateArticleForAuthor(Guid authorId, [FromBody] ArticleForCreationDto article) { if (article == null) { return(BadRequest()); } if (article.Description == article.Title) { ModelState.AddModelError(nameof(ArticleForCreationDto), "The provided description should be different from the title."); } if (!ModelState.IsValid) { // return 422 return(new UnprocessableEntityObjectResult(ModelState)); } if (!_libraryRepository.AuthorExists(authorId)) { return(NotFound()); } var articleEntity = Mapper.Map <Article>(article); _libraryRepository.AddArticleForAuthor(authorId, articleEntity); if (!_libraryRepository.Save()) { throw new Exception($"Creating a article for author {authorId} failed on save."); } var articleToReturn = Mapper.Map <ArticleDto>(articleEntity); return(CreatedAtRoute("GetArticleForAuthor", new { authorId = authorId, id = articleToReturn.Id }, articleToReturn)); }