Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }