public IActionResult CreateAuthorCollection([FromBody] IEnumerable <AuthorForCreationDto> authorCollection) { if (authorCollection == null) { return(BadRequest()); } var authorEntities = Mapper.Map <IEnumerable <Author> >(authorCollection); foreach (var author in authorEntities) { _libraryRepository.AddAuthor(author); } if (!_libraryRepository.Save()) { throw new Exception("Creating an author collection failed on save."); } var authorCollectionToReturn = Mapper.Map <IEnumerable <AuthorDto> >(authorEntities); var idsAsString = string.Join(",", authorCollectionToReturn.Select(a => a.Id)); return(CreatedAtRoute("GetAuthorCollection", new { ids = idsAsString }, authorCollectionToReturn)); // return Ok(); }
public IActionResult CreateAuthor([FromBody] AuthorForCreationDto author) { if (author == null) { return(BadRequest()); } var authorEntity = Mapper.Map <Author>(author); _libraryRepository.AddAuthor(authorEntity); if (!_libraryRepository.Save()) { return(StatusCode(500, "A problem happened with handling your request.")); } var authorToReturn = Mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { id = authorToReturn.Id }, authorToReturn)); }