Example #1
0
        public BookModel CreateBook(BookModel booksModel)
        {
            var bookEntity   = _mapper.Map <BookEntity>(booksModel);
            var bookToReturn = _libraryRepository.CreateBook(bookEntity);

            return(_mapper.Map <BookModel>(bookToReturn));
        }
        public Book AddBook(int authorId, Book book)
        {
            ValidateAuthor(authorId);
            book.AuthorId = authorId;
            var bookCreated = authorsRepository.CreateBook(book);

            return(bookCreated);
        }
Example #3
0
        public IActionResult Post(Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }

            context.CreateBook(book);
            return(Ok(book));
        }
        public Book AddBook(int authorId, Book book)
        {
            ValidateAuthor(authorId);
            if (book.AuthorId != null && authorId != book.AuthorId)
            {
                throw new BadRequestOperationException("URL author id and Book.AuthorId should be equal");
            }

            book.AuthorId = authorId;
            var bookCreated = libraryRepository.CreateBook(book);

            return(bookCreated);
        }
Example #5
0
        public async Task <Book> AddBookAsync(int authorId, Book book)
        {
            if (book.AuthorId != null && authorId != book.AuthorId)
            {
                throw new BadRequestOperationException("URL author id and Book.AuthorId should be equal");
            }
            book.AuthorId = authorId;
            var authorEntity = await validatAuthorId(authorId);

            var bookEntity = mapper.Map <BookEntity>(book);

            libraryRepository.CreateBook(bookEntity);
            if (await libraryRepository.SaveChangesAsync())
            {
                return(mapper.Map <Book>(bookEntity));
            }
            throw new Exception("There were an error with the DB");
        }