Esempio n. 1
0
        public bool Remove_Book(objBook t_book)
        {
            try
            {
                DataContext          dbConnection = Create_DBConnection();
                Table <Book.db_Book> bookTable    = dbConnection.GetTable <Book.db_Book>();

                //Convert DB search to objects
                Book.db_Book removeBook = new Book.db_Book
                {
                    Pkey_1    = t_book.PK,
                    Name      = t_book.Name,
                    ISBN      = t_book.ISBN,
                    Author    = t_book.Author,
                    Publisher = t_book.Publisher
                };
                bookTable.Attach(removeBook);
                bookTable.DeleteOnSubmit(removeBook);
                dbConnection.SubmitChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public bool Add_Book(objBook t_book)
        {
            bool returnValue = true;

            try
            {
                //Get DB connction
                var dbConnection = Create_DBConnection();

                Book.db_Book newBook = new Book.db_Book
                {
                    Name      = t_book.Name,
                    ISBN      = t_book.ISBN,
                    Author    = t_book.Author,
                    Publisher = t_book.Publisher,
                    Amount    = t_book.Amount,
                    Avaiable  = true
                };

                //Sql insert
                Table <Book.db_Book> reservationTable = dbConnection.GetTable <Book.db_Book>();
                reservationTable.InsertOnSubmit(newBook);
                dbConnection.SubmitChanges();
            }
            catch
            {
                returnValue = false;
            }

            return(returnValue);
        }