static void ReadFromXML()
        {
            TransactionScope tran = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            using (tran)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("../../simple-books.xml");
                string xPathQuery = "/catalog/book";

                XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);
                foreach (XmlNode bookNode in bookList)
                {
                    string  title   = bookNode.GetNodeContent("title");
                    string  isbn    = bookNode.GetNodeContent("isbn");
                    string  author  = bookNode.GetNodeContent("author");
                    decimal price   = ParseNullableDecimal(bookNode.GetNodeContent("price"));
                    string  website = bookNode.GetNodeContent("web-site");

                    BookstoreDAL.AddBook(title, isbn, author, price, website);
                }
                tran.Complete();
            }
        }
Esempio n. 2
0
        private static void ImportComplexBooks()
        {
            #region parseXml

            string filePath = "../../xml/complex-books.xml";
            var    result   = Helpers.DeserializeFromXml <ComplexCatalog>(filePath);

            #endregion

            result.Books.ForEachStoppable(b => BookstoreDAL.AddBook(b.Title, b.ISBN, b.Authors, b.Price, b.Url, b.Reviews));
        }
Esempio n. 3
0
        private static void ImportSimpleBooks()
        {
            #region parseXml

            string filePath = "../../xml/simple-books.xml";
            var    result   = Helpers.DeserializeFromXml <SampleCatalog>(filePath);

            #endregion

            result.Books.ForEachStoppable(b => BookstoreDAL.AddBook(b.Title, b.ISBN, b.Author, b.Price, b.Url));
        }
Esempio n. 4
0
        public async Task <IActionResult> AddNewBook(Books newBook)
        {
            await bd.AddBook(newBook);

            return(RedirectToAction("Index"));
        }