UpdateBook() public method

public UpdateBook ( ) : void
return void
        public ActionResult PostUpdate(int id)
        {
            Book selectedBook = Book.Find(id);

            selectedBook.UpdateBook(Request.Form["book_image"], Request.Form["book_author"], Request.Form["book_title"], Request.Form["book_isbn"], Request.Form["book_publisher"], Double.Parse(Request.Form["book_price"]), int.Parse(Request.Form["quantity"]));
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        private void UpdateBookInfo()
        {
            if (Page.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(Request.QueryString["bookID"]))
                {
                    int      bookID           = Convert.ToInt32(Request.QueryString["bookID"]);
                    string   isbn             = txtISBN.Text;
                    string   title            = txtTitle.Text;
                    int      genreID          = int.Parse(ddlGenres.SelectedValue);
                    string   coverImage       = ddlCoverImages.SelectedItem.Text;
                    string   description      = txtDescription.Text;
                    int      authorID         = int.Parse(ddlAuthors.SelectedValue);
                    int      publisherID      = int.Parse(ddlPublishers.SelectedValue);
                    DateTime publicationDate  = Convert.ToDateTime(txtPublicationDate.Text);
                    int      edition          = int.Parse(txtEdition.Text);
                    string   language         = ddlLanguages.SelectedItem.Text;
                    int      numOfPages       = int.Parse(txtNumOfPages.Text);
                    double   price            = Convert.ToDouble(txtPrice.Text);
                    DateTime registrationDate = Convert.ToDateTime(txtRegistrationDate.Text);

                    //Creates an instace of Book class
                    Book book = new Book(isbn, title, genreID, coverImage, description, authorID, publisherID, publicationDate, edition, language,
                                         numOfPages, price, registrationDate);

                    //Updates the specified book into database
                    book.UpdateBook(bookID, book);
                    divSuccess.Visible = true;
                    ClearTextFields();
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Book b = new Book();

            while (true)
            {
                int choice = b.menu();
                switch (choice)
                {
                case 1:
                    b.AddNewBook();
                    break;

                case 2:
                    b.UpdateBook();
                    break;

                case 3:
                    b.DeleteBook();
                    break;

                case 4:
                    b.DisplayBooks();
                    break;

                case 5:
                    return;
                }
            }
        }
Esempio n. 4
0
        public void HandleCommand(UpdateBookCommand command)
        {
            Book book = DomainRepository.Get <Book>(command.AggregateRootId);

            book.UpdateBook(command.Title, command.Author, command.Description, command.ISBN, command.Pages, command.Inventory);
            DomainRepository.Save(book);
            DomainRepository.Commit();
        }
Esempio n. 5
0
 public ActionResult Update(BookViewModel model)
 {
     if (ModelState.IsValid)
     {
         var book = new Book();
         book.UpdateBook(model);
         _bookService.Update(book);
         _context.SaveChanges();
         ViewData["successMsg"] = "Sua thành công";
     }
     return View(model);
 }
Esempio n. 6
0
 public ActionResult Add(BookViewModel model)
 {
     if (ModelState.IsValid)
     {
         SetViewBag();
         var book = new Book();
         book.UpdateBook(model);
         _bookService.Add(book);
         _context.SaveChanges();
         ViewData["successMsg"] = "Thêm thành công";
     }
     return View();
 }
Esempio n. 7
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                //Create a new book object
                Book book = new Book();

                //Read all required values from the controls
                book.BookID      = int.Parse(lblBookID.Text);
                book.Title       = txtTitle.Text;
                book.CategoryID  = int.Parse(ddlCategory.SelectedValue);
                book.Description = txtDescription.Text;
                book.Author      = txtAuthor.Text;

                if (String.IsNullOrEmpty(txtYear.Text))
                {
                    book.Year = null;
                }
                else
                {
                    book.Year = int.Parse(txtYear.Text);
                }
                //Check if file has been selected
                if (upCoverPhoto.HasFile)
                {
                    //call method to upload picture, method returns the new file name
                    book.CoverPhoto = UploadPicture();
                }
                else
                {
                    //Take existing image name
                    book.CoverPhoto = imgCoverPhoto.DescriptionUrl;
                }
                //Call the method that will run the update SQL command and save changes in the database
                book.UpdateBook();

                //Hide form and display success message
                pnlDetails.Visible = false;
                lblMessage.Text    = "Book Record Updated";
                lblBookID.Text     = "";
            }
        }
        catch (Exception err)
        {
            lblMessage.Text = "An Error has occured " + err.Message;
        }
    }
Esempio n. 8
0
        public void Update_UpdatesBookInDatabase_String()
        {
            //Arrange

            Book testBook = new Book("Robinhood", "Fiction");

            testBook.Save();

            //Act
            testBook.UpdateBook("History", "Comedy");
            Book result = Book.Find(testBook.GetId());

            //Assert
            Assert.AreEqual(testBook, result);
        }
        public void Update_Book_With_Title_And_Categories()
        {
            const string newTitle      = "new title";
            var          newCategories = new List <BookCategory> {
                new BookCategory {
                    BookId = _id, CategoryId = Guid.NewGuid()
                }
            };
            var book = new Book(_id, _title, _categories);


            book.UpdateBook(newTitle, newCategories);

            Assert.Equal(_id, book.Id);
            Assert.Equal(newTitle, book.Title);
            Assert.Equal(newCategories, book.BookCategories.ToList());
            Assert.Equal(Status.Updated, book.Status);
        }
Esempio n. 10
0
        public void Update_BookObject_BooksTable()
        {
            //Arrange
            Book testBook = new Book("img", "Benedict Anderson", "Imagined Communities", "2342349430", "Verso", 21, 1);

            testBook.Save();
            string updatedImage     = "image";
            string updatedAuthor    = "Benedict Anderson";
            string updatedName      = "A Life Beyond Boundaries";
            string updatedIsbn      = "3459854822";
            string updatedPublisher = "HarperCollins";
            double updatedPrice     = 25;
            int    updatedQuantity  = 2;

            //Act
            testBook.UpdateBook(updatedImage, updatedAuthor, updatedName, updatedIsbn, updatedPublisher, updatedPrice, updatedQuantity);
            string result = Book.Find(testBook.GetId()).GetName();

            //Assert
            Assert.AreEqual(updatedName, result);
        }
Esempio n. 11
0
 public ActionResult Edit(BookEditModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Book.UpdateBook(model);
             return RedirectToAction("Details", new {id = model.ID});
         }
         var bcm = Book.GetBookCreateModel();
         model.AuthorList = bcm.AuthorList;
         model.GenreList = bcm.GenreList;
         model.TagList = bcm.TagList;
         return View(model);
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return View("Error");
     }
 }
Esempio n. 12
0
 public IHttpActionResult UpdateBook(string ID, string attribute, string newValue)
 {
     Book.UpdateBook(Setting.PathToLibraryDatabase, ID, attribute, newValue);
     return(Ok($"BookID = {ID} was successfully updated."));
 }