public ActionResult <AuthorDto> CreateAuthor(AuthorForCreationDto author) { var authorEntity = _mapper.Map <Entities.Author>(author); _bookstoreRepository.AddAuthor(authorEntity); _bookstoreRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn)); }
public ActionResult <IEnumerable <AuthorDto> > CreateAuthorCollection( IEnumerable <AuthorForCreationDto> authorCollection) { var authorEntities = _mapper.Map <IEnumerable <Entities.Author> >(authorCollection); foreach (var author in authorEntities) { _courseLibraryRepository.AddAuthor(author); } _courseLibraryRepository.Save(); var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntities); var idsAsString = string.Join(",", authorCollectionToReturn.Select(a => a.Id)); return(CreatedAtRoute("GetAuthorCollection", new { ids = idsAsString }, authorCollectionToReturn)); }