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

            _coursesLibraryRepository.AddAuthor(authorEntity);

            _coursesLibraryRepository.Save();

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

            return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn));
        }
        public ActionResult <IEnumerable <Author> > CreateAuthors(IEnumerable <AuthorForCreation> authorsForCreation)
        {
            var authors = _mapper.Map <IEnumerable <Author> >(authorsForCreation);

            foreach (var author in authors)
            {
                _coursesLibraryRepository.AddAuthor(author);
            }

            _coursesLibraryRepository.Save();

            var authorDtos = _mapper.Map <IEnumerable <AuthorDto> >(authors);

            var idsAsString = string.Join(",", authorDtos.Select(a => a.Id));

            return(CreatedAtRoute("GetAuthorsCollection", new { ids = idsAsString }, authorDtos));
        }