Ejemplo n.º 1
0
        public AuthorDto AddAuthor(NewAuthorDto author)
        {
            var authorEntity = _mapper.Map <Author>(author);

            _repo.AddAuthor(authorEntity);
            _repo.Save();
            return(_mapper.Map <AuthorDto>(authorEntity));
        }
Ejemplo n.º 2
0
        public ActionResult <AuthorDto> CreateAuthor(NewAuthorDto author)
        {
            var newAuthor = _manager.AddAuthor(author);
            var linkedResourceToReturn = newAuthor.ShapeData(null) as IDictionary <string, object>;
            var links = CreateLinksForAuthor(newAuthor.Id, null);

            linkedResourceToReturn.Add("links", links);

            return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourceToReturn["Id"] }, linkedResourceToReturn));
        }
Ejemplo n.º 3
0
        public IActionResult CreateAuthor([FromBody] NewAuthorDto author)
        {
            if (author == null)
            {
                return(BadRequest());
            }

            var authorEntity = Mapper.Map <Data.Author>(author);

            this.repository.AddAuthor(authorEntity);

            if (!repository.Save())
            {
                throw new Exception("Creating an author failed on save");
            }

            var newAuthor = Mapper.Map <AuthorDto>(authorEntity);

            return(CreatedAtRoute("GetAuthor", new { id = newAuthor.Id }, newAuthor));
        }