예제 #1
0
        public IActionResult CreateAuthorWithDateOfDeath(AuthorForCreationWithDateOfDeathDto author)
        {
            var authorEntity = _mapper.Map <Author>(author);

            _bookLibraryRepository.AddAuthor(authorEntity);
            _bookLibraryRepository.Save();

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

            var links = CreateLinksForAuthor(authorToReturn.Id, null);

            var linkedResourceToReturn = _mapper.Map <AuthorDto>(authorEntity)
                                         .ShapeData(null) as IDictionary <string, object>;

            linkedResourceToReturn.Add("links", links);

            return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourceToReturn["Id"] },
                                  linkedResourceToReturn));
        }
        public ActionResult <IEnumerable <AuthorDto> > CreateAuthorCollection(
            IEnumerable <AuthorForCreationDto> authorCollection)
        {
            var authorEntity = _mapper.Map <IEnumerable <Author> >(authorCollection);

            foreach (var author in authorEntity)
            {
                _bookLibraryRepository.AddAuthor(author);
            }

            _bookLibraryRepository.Save();

            var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntity);
            var idsAsString = string.Join(",", authorCollectionToReturn.Select(x => x.Id));

            return(CreatedAtRoute("GetAuthorCollection", new { ids = idsAsString },
                                  authorCollectionToReturn));
        }