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();
}
}
}