Esempio n. 1
0
        public List<Book> GetAllBooks()
        {
            if (string.IsNullOrWhiteSpace(_path))
            {
                throw new ArgumentException("path");
            }
            if (!File.Exists(_path))
            {
                throw new IOException("Couldn't find the file");
            }
            if (Path.GetExtension(_path) != ".xml")
            {
                throw new InvalidOperationException("File format is invalid, please use XML file instead");
            }

            XDocument document = XDocument.Load(_path);

            foreach (var item in document.Element("ArrayOfBook").Elements("Book"))
            {
                Book book= new Book
                {
                    Title = item.Element("Title").Value,
                    ISBN = item.Element("ISBN").Value,
                    Author = item.Element("Author").Value,
                    Publisher = item.Element("Publisher").Value,
                    Pages = int.Parse(item.Element("Pages").Value),
                    ReleaseDate = DateTime.Parse(item.Element("ReleaseDate").Value),
                    Price = Double.Parse(item.Element("Price").Value),
                    SalesRank  = Double.Parse(item.Element("SalesRank").Value),
                    Format = (BookFormatType)Enum.Parse(typeof(BookFormatType),item.Element("Format").Value),
                    Size = double.Parse(item.Element("Size").Value),
                    Summary = item.Element("Summary").Value,
                    ImageSource = item.Element("Image").Value
                };
                _books.Add(book);
            }

            return _books;
        }
Esempio n. 2
0
 public BookViewModel(Book book)
 {
     this.book = book;
 }
Esempio n. 3
0
        private void AddNewBook()
        {
            Book newBook = new Book
            {
                Title = "<New Book>",
                ISBN = "0-000-00000-0",
                Pages = 0,
                ReleaseDate = DateTime.Now,
                Price = 0.0,
                SalesRank = 0,
                Format = BookFormatType.Unknown,
                Size = 0
            };

            SelectedBook = new BookViewModel(newBook);
            Books.Add(SelectedBook);
        }