Exemple #1
0
        public ActionResult <AuthorDto> CreateAuthor([FromBody] AuthorForCreationDto author)
        {
            var authorEntity = _mapper.Map <Author>(author);

            _restApiService.AddAuthor(authorEntity);
            _restApiService.Save();

            var authorToReturn = _mapper.Map <AuthorDto>(authorEntity);

            var links = CreateLinksForAuthor(authorToReturn.Id);

            var linkedResourceToReturn = authorToReturn.AsDictionary();

            linkedResourceToReturn.Add("links", links);

            return(CreatedAtRoute("GetAuthor",
                                  new { authorId = linkedResourceToReturn["Id"] },
                                  linkedResourceToReturn));
        }