public Book Post([FromForm] AddBookDTO book)
        {
            var publisher = new Publisher {
                PublisherName = book.PublisherName
            };

            _context.Attach(publisher);
            var category = new Category {
                CategoryID = book.CategoryID
            };

            _context.Attach(category);
            string Img = _imageService.SaveImg(book.Image);


            var newBook = new Book
            {
                BookImgUrl      = Img,
                ISBN            = book.ISBN,
                Title           = book.Title,
                Category        = category,
                Publisher       = publisher,
                PublicationDate = book.PublicationDate,
                Edition         = book.Edition,
                Pagination      = book.Pagination,
                Price           = book.Price,
                Plot            = book.Plot,
            };

            return(newBook);
        }
Esempio n. 2
0
        public async Task <ActionResult <Book> > PostBook([FromBody] AddBookDTO book)
        {
            var model = _mapper.Map <Book>(book);

            //model.CreatedBy = User.Identity.Name;
            if (await _unitOfWork.Book.AddBookAsync(model))
            {
                return(CreatedAtAction("GetBook", new { id = model.BookId }, model));
            }
            return(BadRequest());
        }
Esempio n. 3
0
        public ActionResult Add(AddBookDTO dto)
        {
            var data = new NameValueCollection();

            data.Add("BookName", dto.BookName);
            data.Add("ISBN", dto.ISBN);
            data.Add("IssueDate", dto.IssueDate.ToString("yyyy-MM-dd"));
            data.Add("Description", dto.Description);

            var commandUnqiueId = ApiRequestWithFormUrlEncodedContent.Post <Guid>($"{_inventoryApiBaseUrl}/api/Books", data);

            return(Json(new { commandUnqiueId = commandUnqiueId }));
        }
Esempio n. 4
0
        public async Task <ActionResult <Book> > PostBook([FromForm] AddBookDTO book)
        {
            if (BookExists(book.ISBN))
            {
                return(BadRequest(new { msg = "DuplicateISBN" }));
            }
            var newWriter = _writerService.Post(book.WriterName);

            foreach (var w in newWriter)
            {
                _context.Writer.Add(w);
            }

            var publisher = _publisherService.Post(book.PublisherName);

            if (publisher != null)
            {
                _context.Publisher.Add(publisher);
            }

            var newBook = _bookService.Post(book);

            _context.Book.Add(newBook);

            var newAuthor = _authorService.Post(newBook, book.WriterName);

            foreach (var a in newAuthor)
            {
                _context.Author.Add(a);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (BookExists(book.ISBN))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetBook", new { id = book.ISBN }, book));
        }
Esempio n. 5
0
        public bool Add(AddBookDTO bookDto, string libraryId)
        {
            bool isNewBook = false;
            var  book      = this.db.Books.FirstOrDefault(b => b.Name == bookDto.Name);

            if (book == null)
            {
                isNewBook = true;
                var authors    = bookDto.Authors;
                var publisher  = this.publisherService.GetPublisher(bookDto.Publisher);
                var categories = bookDto.Categories;
                var rating     = new Rating();

                var imageUri = string.Empty;
                using (var ms = new MemoryStream())
                {
                    bookDto.Picture.CopyTo(ms);
                    var fileBytes = ms.ToArray();
                    imageUri = this.blobStorage.UploadFileToBlob(bookDto.Picture.FileName, fileBytes, bookDto.Picture.ContentType);
                }

                book = new Book
                {
                    Name        = bookDto.Name,
                    Publisher   = publisher,
                    Rating      = rating,
                    PictureName = imageUri,
                    IsRented    = false,
                    IsRemoved   = false,
                    Summary     = bookDto.Summary
                };

                publisher.Books.Add(book);
                SetCategories(categories, book);
                SetAuthors(authors, book);
            }

            SetLibraryBooks(libraryId, book);

            if (isNewBook)
            {
                this.db.Add(book);
            }

            var count = db.SaveChanges();

            return(count != 0);
        }
Esempio n. 6
0
        public IHttpActionResult AddBook([FromBody] AddBookDTO newBook)
        {
            if (newBook != null)
            {
                var  authorId = getAuthorIdByLastName(newBook.AuthorLastName);
                Book b        = new Book {
                    Id       = dbContext.Book.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1,
                    Title    = newBook.Title,
                    AuthorId = authorId,
                    Year     = newBook.Year
                };
                dbContext.Book.Add(b);
                dbContext.SaveChanges();
            }

            return(Ok());
        }
Esempio n. 7
0
 public void AddBook(AddBookDTO dto)
 {
     _commands.Add(new Command("INSERT INTO Book(BookId,BookName,ISBN,DateIssued,Description) values(@bookId, @bookName, @isbn, @dateIssued, @description)", new List <SqlParameter> {
         new SqlParameter {
             ParameterName = "@bookId", SqlDbType = SqlDbType.UniqueIdentifier, Value = dto.BookId
         },
         new SqlParameter {
             ParameterName = "@bookName", SqlDbType = SqlDbType.NVarChar, Value = dto.BookName
         },
         new SqlParameter {
             ParameterName = "@isbn", SqlDbType = SqlDbType.NVarChar, Value = dto.ISBN
         },
         new SqlParameter {
             ParameterName = "@dateIssued", SqlDbType = SqlDbType.DateTime2, Value = dto.DateIssued
         },
         new SqlParameter {
             ParameterName = "@description", SqlDbType = SqlDbType.NVarChar, Value = dto.Description
         }
     }));
 }
Esempio n. 8
0
 public IActionResult AddBook([FromBody] AddBookDTO addBookDTO)
 {
     if (ModelState.IsValid)
     {
         AddBookCommand addBookCommand = new AddBookCommand(addBookDTO.Title, addBookDTO.AuthorId,
                                                            addBookDTO.ReleaseYear);
         try
         {
             var result = _messages.Dispatch(addBookCommand);
             return(FromResult(result));
         }
         catch (DomainException ex)
         {
             _logger.LogError(ex.Message);
             return(Error(ex.Message));
         }
         catch (Exception ex)
         {
             _logger.LogCritical(ex.Message);
             return(StatusCode(500));
         }
     }
     return(BadRequest());
 }
Esempio n. 9
0
        public ActionResult Add(AddBookDTO dto)
        {
            var commandUnqiueId = ApiRequest.Post <Guid>($"{_inventoryApiBaseUrl}/api/Books", dto);

            return(Json(new { commandUnqiueId = commandUnqiueId }));
        }
Esempio n. 10
0
		public ActionResult Add(AddBookDTO dto)
		{
			var commandUnqiueId = ApiRequest.Post<Guid>($"{_apiGatewayUrl}/api/books", dto);

			return Json(new { commandUnqiueId = commandUnqiueId });
		}