public ActionResult <AuthorsDto> CreateAuthor(AuthorForCreationDto authorForCreationDto) { var authorEntity = _mapper.Map <Entities.Author>(authorForCreationDto); _courseLibraryRepository.CreateAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorsDto>(authorEntity); return(CreatedAtRoute("GetAuthors", new { authorId = authorToReturn.Id }, authorToReturn)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorForCreationDto authorForCreationDto) { if (authorForCreationDto == null) { return(BadRequest()); } var author = _mapper.Map <Author>(authorForCreationDto); var authorToReturn = _mapper.Map <AuthorDto>(author); _repository.CreateAuthor(author); return(CreatedAtRoute("", new { authorId = author.Id }, authorToReturn)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorDtoForCreation model) { if (!ModelState.IsValid) { return(BadRequest()); } var authorEntity = _mapper.Map <Author>(model); _courseLibraryRepository.CreateAuthor(authorEntity); var authorDto = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorDto.Id }, authorDto)); }
public IActionResult CreateAuthors(IEnumerable <AuthorForCreationDto> authors) { if (authors == null) { return(BadRequest()); } var authorsToCreate = _mapper.Map <IEnumerable <Entities.Author> >(authors); foreach (var author in authorsToCreate) { _courseLibraryRepository.CreateAuthor(author); } _courseLibraryRepository.Save(); var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorsDto> >(authorsToCreate); var idsAsString = string.Join(",", authorCollectionToReturn.Select(x => x.Id)); return(CreatedAtRoute("GetAuthorCollection", new { ids = idsAsString }, authorCollectionToReturn)); }