public async Task <IActionResult> AddBooks(BookInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(input));
            }

            var result = await booksService.AddBook(input.Title, input.AuthorId,
                                                    input.PublisherId, input.CategoryId, input.PublicationYear, input.Isbn, input.Description);

            string message = result.Message;
            int    id      = result.ResultId;

            if (id != 0)
            {
                await booksService.EditPictureName(id);

                System.IO.Directory.CreateDirectory(environment.WebRootPath + "/images");
                using (var file = System.IO.File.OpenWrite(environment.WebRootPath + $"/images/{id}.png"))
                {
                    await input.Image.CopyToAsync(file);
                }
            }


            return(RedirectToAction("Index", "DatabaseSeeding", new { message = message, id = id }));
        }
Ejemplo n.º 2
0
        public ActionResult <Book> PostBook(int authorId, [FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var bookCreated = booksService.AddBook(authorId, book);
                return(Created($"/api/authors/{authorId}/books/{book.Id}", bookCreated));
            }
            catch (InvalidOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (NotFoundItemException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <Guid> Handle(AddNewBookCommand request, CancellationToken cancellationToken)
        {
            var bookForDb = AddNewBookCommand.ConvertToBook(request);

            _service.AddBook(bookForDb);
            await _service.SaveChangesAsync();


            return(bookForDb.Id);
        }
Ejemplo n.º 4
0
        public IActionResult CreateBook(Book book)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateBook"));
            }

            _booksService.AddBook(book);

            return(View("BookCreated", book));
        }
        public IActionResult PostBook([FromBody] Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }
            _booksService.AddBook(book);

            return(CreatedAtRoute(nameof(GetBook),
                                  new { id = book.BookId }, book));
        }
        public ActionResult Post([FromBody] Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }

            // int nextId = _booksService.GetBooks().Max(b => b.BookId) + 1;
            // book.BookId = nextId;
            _booksService.AddBook(book);
            return(CreatedAtRoute("GetBookById", new { id = book.BookId }, book));
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <Guid> > Handle(AddBookCollectionCommand request,
                                                       CancellationToken cancellationToken)
        {
            var booksForDb = request.ListOfBooks.Select(AddNewBookCommand.ConvertToBook).ToList();

            foreach (var book in booksForDb)
            {
                _service.AddBook(book);
            }

            await _service.SaveChangesAsync();

            var id = booksForDb.Select(b => b.Id);

            return(id);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> AddBook([FromBody] BookRequest bookRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await GetCurrentUser();

            var book = AutoMapper.Mapper.Map <Book>(bookRequest);

            book.UserId = user.Id;
            book.User   = user;

            await _booksService.AddBook(book);

            return(Ok());
        }
Ejemplo n.º 9
0
        public IActionResult AddBook([FromBody] BookView book)
        {
            if (book == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(StatusCode(412, "modelstate is not valid"));
            }

            try {
                var newBook = _booksService.AddBook(book);
                return(CreatedAtRoute("GetBookById", new { bookId = newBook.Id }, newBook));
            } catch (AlreadyExistsException e) {
                return(StatusCode(409, e.Message));
            }
        }
Ejemplo n.º 10
0
        public void OnSave()
        {
            if (SelectedBook == null)
            {
                return;
            }

            if (_createdNew)
            {
                _booksService.AddBook(SelectedBook);
                _createdNew = false;
                _eventAggregator.GetEvent <RefreshBooksEvent>().Publish();
            }
            else
            {
                _booksService.UpdateBook(SelectedBook);
            }
        }
Ejemplo n.º 11
0
 public Task Post([FromBody] Book value) => _booksService.AddBook(value);
Ejemplo n.º 12
0
 public ActionResult <Book> PostBook([FromBody] Book book)
 {
     _booksService.AddBook(book);
     return(CreatedAtRoute("GetBookById", new { id = book.BookId }, book));
 }
Ejemplo n.º 13
0
 public IActionResult Create1(Book book)
 {
     _booksService.AddBook(book);
     return(View("Index"));
 }
Ejemplo n.º 14
0
        public IActionResult PostBook([FromBody] Book value)
        {
            Book newBook = _booksService.AddBook(value);

            return(Created($"api/Books/{newBook.BookId}", newBook));
        }
 public ActionResult <Book> PostBook([FromBody] Book book)
 {
     book = _booksService.AddBook(book);
     return(Ok(book));
 }
Ejemplo n.º 16
0
 public void Post([FromBody] Book value)
 {
     _booksService.AddBook(value);
 }
 public void Post(Book value)
 {
     _booksService.AddBook(value);
 }
Ejemplo n.º 18
0
        public IActionResult PostBook([FromBody] Book book)
        {
            var bookResult = _booksService.AddBook(book);

            return(Ok(bookResult));
        }