Exemplo n.º 1
0
        public async Task <ActionResult <BookDetailResource> > DeleteBook(int id)
        {
            BookResponse response = await _BookService.DeleteAsync(id);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            BookDetailResource deletedResource = _mapper.Map <BookDetailResource>(response.Book);

            return(Ok(deletedResource));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <BookDetailResource> > GetBook(int id)
        {
            BookResponse response = await _BookService.FindByIdAsync(id);

            if (!response.Success)
            {
                return(NotFound(response.Message));
            }

            BookDetailResource resource = _mapper.Map <BookDetailResource>(response.Book);

            return(Ok(resource));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <BookDetailResource> > PutBook(int id, BookSaveResource resource)
        {
            Book         book     = _mapper.Map <Book>(resource);
            BookResponse response = await _BookService.UpdateAsync(id, book);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            BookDetailResource updatedResource = _mapper.Map <BookDetailResource>(response.Book);

            return(Ok(updatedResource));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <BookDetailResource> > PostBook(BookSaveResource resource)
        {
            Book         book     = _mapper.Map <Book>(resource);
            BookResponse response = await _BookService.SaveAsync(book);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            BookDetailResource savedResource = _mapper.Map <BookDetailResource>(response.Book);

            return(CreatedAtAction(nameof(GetBook), new { id = savedResource.Id }, savedResource));
        }