Bookstore.DataAccessLayer.BooksDAO.ComplexImportOfBook C# (CSharp) Method

ComplexImportOfBook() public method

public ComplexImportOfBook ( IList authorsNames, string title, IList reviewTransferObjects, string isbn, decimal price, string webSite ) : void
authorsNames IList
title string
reviewTransferObjects IList
isbn string
price decimal
webSite string
return void
        public void ComplexImportOfBook(
            IList<string> authorsNames,
            string title,
            IList<ReviewTransferObject> reviewTransferObjects,
            string isbn,
            decimal? price,
            string webSite)
        {
            BookstoreEntities context = new BookstoreEntities();

            Book newBook = new Book();
            newBook.ISBN = isbn;
            newBook.Title = title;
            newBook.Price = price;
            newBook.WebSite = webSite;

            foreach (string authorName in authorsNames)
            {
                Author author = CreateOrLoadAuthor(context, authorName);
                newBook.Authors.Add(author);
            }

            foreach (ReviewTransferObject reviewTransferObject in reviewTransferObjects)
            {
                Review review = SerializeToReview(context, reviewTransferObject);
                newBook.Reviews.Add(review);
            }

            context.Books.Add(newBook);
            context.SaveChanges();
        }

Usage Example

        static void ComplexBooksImport(BooksDAO booksDao, string xmlFilePath)
        {
            XmlDocument catalogDocument = new XmlDocument();
            catalogDocument.Load(xmlFilePath);
            string xPathBooksQuery = "/catalog/book";
            XmlNodeList bookNodesList = catalogDocument.SelectNodes(xPathBooksQuery);
            foreach (XmlNode bookNode in bookNodesList)
            {
                string title = GetInnerXml(bookNode, "title").Trim();

                IList<string> authorNames = new List<string>();
                GetAuthors(bookNode, authorNames);

                IList<ReviewTransferObject> reviewTransferObjects =
                    new List<ReviewTransferObject>();
                GetReviews(bookNode, reviewTransferObjects);

                string isbn = GetInnerXml(bookNode, "isbn");

                string webSite = GetInnerXml(bookNode, "web-site");
                if (webSite != null)
                {
                    webSite = webSite.Trim();
                }

                decimal? price = null;
                string priceAsString = GetInnerXml(bookNode, "price");
                if (priceAsString != null)
                {
                    price = decimal.Parse(priceAsString);
                }

                using (TransactionScope transcationScope = new TransactionScope(TransactionScopeOption.Required,
                    new TransactionOptions() { IsolationLevel = IsolationLevel.RepeatableRead }))
                {
                    booksDao.ComplexImportOfBook(authorNames, title, reviewTransferObjects, isbn, price, webSite);
                    transcationScope.Complete();
                }
            }
        }