Inheritance: Entity
Exemple #1
0
 public BookDetailViewModel(Book book)
 {
     this.Reviews = new ObservableCollection<ReviewViewModel>();
     this.BuyLinks = new ObservableCollection<BuyLinkViewModel>();
     TheBook = new Book();
     TheBook = book;
 }
Exemple #2
0
 public void UpdateViewModel(Book book)
 {
     TheBook = book;
     isLoaded = true;
 }
Exemple #3
0
        public List<Book> BookParse(string xmlFile)
        {
            List<Book> bl = new List<Book>();

            XNamespace d = @"http://www.w3.org/2005/Atom";
            XNamespace db = @"http://www.douban.com/xmlns/";
            XNamespace gd = @"http://schemas.google.com/g/2005";
            XNamespace opensearch = @"http://a9.com/-/spec/opensearchrss/1.0/";

            XDocument doc = XDocument.Parse(xmlFile);
            foreach (XElement entry in doc.Descendants(d + "entry"))
            {
                Book book = new Book();
                foreach (XElement element in entry.Descendants(d + "title"))
                {
                    book.Title = element.Value;
                }

                foreach (XElement element in entry.Descendants(d + "summary"))
                {
                    book.Summary = element.Value;
                }

                foreach (XElement element in entry.Descendants(d + "link"))
                {
                    if (element.Attribute("rel").Value == "image")
                    {
                        book.Imageurl = element.Attribute("href").Value;
                    }
                    else if (element.Attribute("rel").Value == "alternate")
                    {
                        book.Weblink = element.Attribute("href").Value;
                    }
                }

                //对于加了冒号前缀的元素,使用下列代码
                foreach (XElement element in entry.Descendants(db + "attribute"))
                {
                    switch (element.Attribute("name").Value)
                    {
                        case "isbn13":
                            book.Isbn = element.Value;
                            break;
                        case "pages":
                            book.Pages = element.Value;
                            break;
                        case "author":
                            book.Author.Add(element.Value);
                            break;
                        case "price":
                            book.Price = element.Value;
                            break;
                        case "publisher":
                            book.Publisher = element.Value;
                            break;
                        case "pubdate":
                            book.Pubdate = element.Value;
                            break;
                        case "author-intro":
                            book.AuthorIntro = element.Value;
                            break;
                        case "binding":
                            book.Binding = element.Value;
                            break;
                        case "translator":
                            book.Translator.Add(element.Value);
                            break;
                        case "subtitle":
                            book.Subtitle = element.Value;
                            break;
                    }
                }

                foreach (XElement element in entry.Descendants(gd + "rating"))
                {
                    book.Rating.Average= element.Attribute("average").Value;
                    book.Rating.RatersNum = element.Attribute("numRaters").Value;
                }

                foreach (XElement element in entry.Descendants(db + "tag"))
                {
                    BookTag tag = new BookTag();
                    tag.Tag = element.Attribute("name").Value;
                    tag.Count = element.Attribute("count").Value;
                    book.Tags.Add(tag);
                }

                bl.Add(book);
            }

            return bl;
        }
Exemple #4
0
 public ItemViewModel()
 {
     TheBook = new Book();
 }
Exemple #5
0
 public ItemViewModel(Book book)
 {
     TheBook = new Book();
     TheBook = book;
 }
Exemple #6
0
 public void UpdateViewModel(Book book)
 {
     TheBook = book;
 }
 private void InvalidBook()
 {
     Dispatcher.BeginInvoke(() =>
     {
         Book nullBook = new Book();
         bookDetailViewModel.UpdateViewModel(nullBook);//null book
         this.DataContext = bookDetailViewModel;
         noBasicInfo.Visibility = System.Windows.Visibility.Visible;
         noSummaryInfo.Visibility = System.Windows.Visibility.Visible;
         noReview.Visibility = System.Windows.Visibility.Visible;
         noBuyinfo.Visibility = System.Windows.Visibility.Visible;
     });
 }