Ejemplo n.º 1
0
        public async Task <IActionResult> AddNewBook([FromBody] BookModel bookModel)
        {
            var id = await _bookRepository.AddBookAsync(bookModel);

            //return Ok(books);
            return(CreatedAtAction(nameof(GetBookbyId), new { id = id, Controller = "books" }, id));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Book> > Post(Book book)
        {
            var newBook = await _repository.AddBookAsync(book);

            _logger.LogInformation(
                ApplicationEvents.BookCreated,
                "Added book with id '{Id}'.",
                newBook.Id);

            return(CreatedAtRoute("GetById", new { id = newBook.Id }, newBook));
        }
Ejemplo n.º 3
0
 public async Task <Book> AddBookAsync(Book book)
 {
     try
     {
         return(await _repo.AddBookAsync(book));
     }
     catch (DataException e)
     {
         _logger.Error(e.Message);
         throw new DataException(e.Message);
     }
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddBook([FromBody] BookDtoRequest bookDto)
        {
            var tags   = bookDto.Tags;
            var book   = mapper.Map <Book>(bookDto);
            var result = await repository.AddBookAsync(book, tags.ToArray());

            if (result == null)
            {
                return(BadRequest("Book Wasn't added successfully"));
            }
            return(Ok(result));
        }
Ejemplo n.º 5
0
        public async Task AddBookAsync(Guid id, string title, string author, string category, string publishingCompany,
                                       string description, int pages)
        {
            var book = await _bookRepository.GetAsync(id);

            if (book != null)
            {
                throw new Exception($"Book {id} is exist");
            }

            book = new Book(id, title, author, category, publishingCompany, description, pages);
            await _bookRepository.AddBookAsync(book);
        }
Ejemplo n.º 6
0
        public async Task <Book> CreateBookAsync(BookCreateDTO newBook)
        {
            var bookToSave = new Book
            {
                Name        = newBook.Name,
                Description = newBook.Description,
                ImageUrl    = newBook.ImageUrl,
                Price       = newBook.Price,
                InStock     = newBook.InStock
            };

            var author = await GetOrCreateAuthorAsync(newBook);

            bookToSave.AuthorId = author.AuthorId;
            bookToSave.Author   = author;

            var book = await bookRepository.AddBookAsync(bookToSave);

            return(book);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> AddBook([FromBody] SaveBookResource sbResource)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var book = mapper.Map <SaveBookResource, Book>(sbResource);
                book.LastUpdate = DateTime.Now;
                bookRepository.AddBookAsync(book);
                await unitOfWork.CompleteAsync();

                var newBook = await bookRepository.GetBookByIdAsync(book.Id);

                _logger.LogInformation(new EventId(), null, newBook, null);
                return(Ok(mapper.Map <Book, BookResource>(newBook)));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 8
0
 public async Task <bool> AddBookAsync(Book book)
 {
     return(await _bookDataStore.AddBookAsync(book));
 }
Ejemplo n.º 9
0
 public async Task AddBook(Guid id, string title, string author, string publishingHouse, int year)
 {
     var book = new Book(id, title, author, publishingHouse, year);
     await _bookRepository.AddBookAsync(book);
 }
Ejemplo n.º 10
0
        public BooksMutation(IBookRepository bookRepository, IAuthorRepository authorRepository, IAuthorMessageService authorMessageService, IBookMessageService bookMessageService)
        {
            FieldAsync <BookType>(
                "createBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookAddedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.AddBookAsync(book);
                bookMessageService.AddBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "updateBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "book"
            }),
                resolve: async context =>
            {
                var book = context.GetArgument <Book>("book");
                await bookRepository.UpdateBookAsync(book);
                bookMessageService.UpdateBookMessage(book);
                return(book);
            });

            FieldAsync <BookType>(
                "deleteBook",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id   = context.GetArgument <int>("id");
                var book = await bookRepository.GetBookAsync(id);
                await bookRepository.DeleteBookAsync(book);
                bookMessageService.DeleteBookMessage(book);
                return(book);
            });

            FieldAsync <AuthorType>(
                "createAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <AuthorAddedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.AddAuthorAsync(author);
                authorMessageService.AddAuthorMessage(author);
                return(author);
            });

            FieldAsync <AuthorType>(
                "updateAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookUpdatedType> > {
                Name = "author"
            }),
                resolve: async context =>
            {
                var author = context.GetArgument <Author>("author");
                await authorRepository.UpdateAuthorAsync(author);
                authorMessageService.UpdateAuthorMessage(author);
                return(author);
            });


            FieldAsync <AuthorType>(
                "deleteAuthor",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id     = context.GetArgument <int>("id");
                var author = await authorRepository.GetAuthorAsync(id);
                await authorRepository.DeleteAuthorAsync(author);
                authorMessageService.DeleteAuthorMessage(author);
                return(author);
            });
        }
 public async Task AddBookAsync(BookViewModel bookViewModel)
 {
     var book = _mapper.Map <Book>(bookViewModel);
     await _bookRepository.AddBookAsync(book);
 }
Ejemplo n.º 12
0
        public Task <Book> AddBookAsync(Book book)
        {
            var response = _book.AddBookAsync(book);

            return(response);
        }