Пример #1
0
 public BookCreateCommand Map(BookPostRequestDto bookDto)
 {
     return(new BookCreateCommand
     {
         Asin = bookDto.Asin,
         Author = bookDto.Author,
         BookUrl = bookDto.BookUrl,
         ImageUrl = bookDto.ImageUrl,
         Title = bookDto.Title
     });
 }
Пример #2
0
        public async Task <ActionResult <BookPostResponseDto> > PostBook(BookPostRequestDto bookPost)
        {
            try
            {
                var createCommand = _bookMapper.Map(bookPost);
                var book          = await _bookService.CreateBookAsync(createCommand);

                var response = _bookMapper.MapToBookPostResponse(book);
                return(CreatedAtAction(nameof(GetBook), new { id = book.BookId }, response));
            }
            catch (ConflictEntityException ex)
            {
                return(Conflict(new
                {
                    message = "Book already exists",
                    bookId = ex.ReferenceId
                }));
            }
        }