/// <summary> /// Copy constructor /// </summary> /// <param name="bookInfo"></param> public NBook(NBook bookInfo) { Name = bookInfo.Name; Author = bookInfo.Author; Description = bookInfo.Description; Image = (NImage)bookInfo.Image.DeepClone(); Price = bookInfo.Price; }
/// <summary> /// Loads a book with the specified index /// </summary> /// <param name="index"></param> void LoadBook(int index) { m_nSelectedBook = NMath.Clamp(0, m_Books.Count - 1, index); NBook book = m_Books[m_nSelectedBook]; m_SelectedBookImage.Geometry.Fill = new NImageFill((NImage)book.Image.DeepClone()); m_SelectedBookTitle.Text = book.Name; m_SelectedBookDescription.Text = book.Description; }
/// <summary> /// Gets the min Width and Height of all book images /// </summary> /// <returns></returns> NSize GetMinBookImageSize() { NSize size = new NSize(double.MaxValue, double.MaxValue); for (int i = 0; i < m_Books.Count; i++) { NBook book = m_Books[i]; if (book.Image.Width < size.Width) { size.Width = book.Image.Width; } if (book.Image.Height < size.Height) { size.Height = book.Image.Height; } } return(size); }
/// <summary> /// Adds a book to the shopping cart. /// </summary> /// <param name="book"></param> /// <param name="example"></param> public void AddItem(NBook book, NWidgetHostingExample example) { // try find an item with the same name. if such exists -> incerase quantity and rebuild shopping cart widget for (int i = 0; i < Items.Count; i++) { if (Items[i].Name == book.Name) { Items[i].Quantity++; example.m_ShoppingCartWidget.Content = CreateWidget(example); return; } } // add new item and rebuild shopping cart widget NShoppingCartItem item = new NShoppingCartItem(); item.Name = book.Name; item.Price = book.Price; item.Quantity = 1; Items.Add(item); example.m_ShoppingCartWidget.Content = CreateWidget(example); }