Bookstore.DataAccessLayer.BooksDAO.SimpleImportOfBook C# (CSharp) Метод

SimpleImportOfBook() публичный Метод

public SimpleImportOfBook ( string authorName, string title, string isbn, decimal price, string webSite ) : void
authorName string
title string
isbn string
price decimal
webSite string
Результат void
        public void SimpleImportOfBook(string authorName, string title, string isbn, decimal? price, string webSite)
        {
            BookstoreEntities context = new BookstoreEntities();

            Book newBook = new Book();
            Author author = CreateOrLoadAuthor(context, authorName);
            newBook.Authors.Add(author);
            newBook.ISBN = isbn;
            newBook.Price = price;
            newBook.Title = title;
            newBook.WebSite = webSite;

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

Usage Example

        static void SimpleBooksImport(BooksDAO booksDao, string xmlFilePath)
        {
            XmlDocument catalogDocument = new XmlDocument();
            catalogDocument.Load(xmlFilePath);
            string xPathQuery = "/catalog/book";
            XmlNodeList bookNodesList = catalogDocument.SelectNodes(xPathQuery);
            foreach (XmlNode bookNode in bookNodesList)
            {
                string author = GetInnerXml(bookNode, "author").Trim();
                string title = GetInnerXml(bookNode, "title").Trim();
                string isbn = GetInnerXml(bookNode, "isbn");
                if (isbn != null)
                {
                    isbn = isbn.Trim();
                }

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

                booksDao.SimpleImportOfBook(author, title, isbn, price, webSite);
            }
        }