private static void WriteReviewElement(Review review, XmlTextWriter writer)
        {
            writer.WriteStartElement("result-set");
            if (review.CreationDate != null)
            {
                writer.WriteElementString("data", review.CreationDate.ToString());
            }

            writer.WriteElementString("content", review.Text);

            writer.WriteStartElement("book");
            writer.WriteElementString("title", review.Book.Title);
            if (review.Book.Authors != null && review.Book.Authors.Count > 0)
            {
                writer.WriteElementString("authors", string.Join(", ",review.Book.Authors));
            }

            if (review.Book.ISBN != null)
	        {
		         writer.WriteElementString("isbn", review.Book.ISBN);
	        }

            if (review.Book.WebSite != null)
	        {
		         writer.WriteElementString("url", review.Book.WebSite);
	        }

            writer.WriteEndElement();
        }
        private static Review ParseReview(XmlNode review)
        {
            var newReview = new Review
            {                
                Text = review.GetText()
            };

            var authorText = review.Attributes[Author].GetText();
            if (authorText != null)
	        {
                newReview.Author = new Author { Name = authorText };
	        }                       

            var dateString = review.Attributes[Date].GetText();
            var parsedDate = ParseDate(dateString);

            if (parsedDate != null)
            {
                newReview.CreationDate = DateTime.Parse(parsedDate.ToString());
            }

            return newReview;
        }
示例#3
0
        public static void ImportBooksAuthorsAndReviews(string bookTitle, string isbn,
            decimal? price, string webSite, List<string> authorsNames, List<ReviewData> reviewsData)
        {
            using (BookstoreEntities dbContext = new BookstoreEntities())
            {
                Book newBook = new Book
                {
                    Title = bookTitle.ToLower(),
                    ISBN = isbn,
                    Price = price,
                    website = webSite,
                };

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

                foreach (ReviewData reviewData in reviewsData)
                {
                    Review newReview = new Review()
                    {
                        Content = reviewData.Content,
                        CreationDate = reviewData.Date,
                    };

                    if (reviewData.AuthorName != null)
                    {
                        newReview.Author = CreateOrLoadAuthor(dbContext, reviewData.AuthorName);
                    }

                    newBook.Reviews.Add(newReview);
                }

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