public AuthorReadDto GetAuthorReadDto(Author author) { AuthorReadDto authorDto = _mapper.Map <AuthorReadDto>(author); authorDto.Books = author.AuthorsBooks.Select(ab => new BookForReadAuthorDto(ab.BookId, ab.Book.Title, ab.Book.ReleaseDate, ab.Book.Sinopse)).ToArray(); return(authorDto); }
public async Task <ActionResult> Create([FromBody] AuthorCreateDto authorCreateDto) { Author author = await _controllerServices.FilledAuthorOnCreateAsync(authorCreateDto); await _authorRepository.CreateAsync(author); AuthorReadDto authorReadDto = _controllerServices.GetAuthorReadDto(author); return(CreatedAtRoute("GetAuthorById", new { author.Id }, authorReadDto)); }
public async Task <ActionResult <AuthorReadDto> > GetById(int id) { Author authorFromDb = await _authorRepository.FindAByIdWithoutTrackingAsync(id); if (authorFromDb is null) { return(NotFound()); } AuthorReadDto authorReadDto = _controllerServices.GetAuthorReadDto(authorFromDb); return(Ok(authorReadDto)); }