Ejemplo n.º 1
0
        public ActionResult <Dto.Author> CreateAuthor(Dto.AuthorRequest authorRequest)
        {
            var  author = _mapper.Map <Author>(authorRequest);
            Book book   = null;

            if (authorRequest.BookId != null)
            {
                book = _bookRepository.GetBook(authorRequest.BookId);
            }
            _repository.CreateAuthor(author, book);
            if (_repository.SaveChanges() == false)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(CreatedAtAction("GetAuthor", new { Id = author.Id }, _mapper.Map <Dto.Author>(author)));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateAuthor(int id, Dto.AuthorRequest authorRequest)
        {
            var author = _repository.GetAuthor(id);

            if (author == null)
            {
                return(NotFound());
            }

            _mapper.Map(authorRequest, author);
            _repository.UpdateAuthor(author);
            if (_repository.SaveChanges() == false)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(NoContent());
        }