Esempio n. 1
0
        /// <summary>
        /// Adds the specified product to cart
        /// </summary>
        /// <param name="productViewModel">The view model of the product row viewer to add product</param>
        public void AddToCart(ProductRowViewerViewModel productViewModel)
        {
            var viewModel = new OrderRowViewerViewModel
                            (
                CurrentCart.Count + 1,
                Order.CurrentOrder.ID,
                "1",
                "0",
                productViewModel
                            );

            viewModel.CanDelete = true;

            // Updates the list price
            viewModel.TotalPriceChanged += () => OnPropertyChanged(nameof(TotalPrice));
            viewModel.Deleted           += DeleteItem;

            if (!mIsSearching)
            {
                CurrentCart.Add(viewModel);
                Items.Add(viewModel);
            }
            else
            {
                CurrentCart.Add(viewModel);
            }

            // Make the product not available to be added to the cart again
            // Because the qunatity of the product can be specified in the (CartPage)
            productViewModel.IsOutFromCart = false;

            OnPropertyChanged(nameof(TotalPrice));
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the product from the cart
        /// </summary>
        /// <param name="viewModel">The view model of the product row viewer to remove the product</param>
        public void RemoveFromCart(ProductRowViewerViewModel viewModel)
        {
            // Removing it from the (Items) list if there is no searching now
            if (!mIsSearching)
            {
                foreach (OrderRowViewerViewModel item in Items)
                {
                    if (item.ProductViewModel.Equals(viewModel))
                    {
                        Items.Remove(item);
                        break;
                    }
                }
            }

            // Removing it from the cart
            foreach (OrderRowViewerViewModel item in CurrentCart)
            {
                if (item.ProductViewModel.Equals(viewModel))
                {
                    CurrentCart.Remove(item);
                    break;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initialize a new instance from <see cref="OrderRowViewerViewModel"/> class
 /// </summary>
 /// <param name="rowNumber">The row number which holds the order line</param>
 /// <param name="orderID">The ID of the order which contains the order line to show</param>
 /// <param name="quantityString">The quantity of the product to sell</param>
 /// <param name="discountString">The applied discount</param>
 /// <param name="productViewModel">The view model to get product data from it</param>
 public OrderRowViewerViewModel(int rowNumber, int orderID, string quantityString, string discountString,
                                ProductRowViewerViewModel productViewModel) : this(rowNumber, orderID, quantityString, discountString)
 {
     this.ProductViewModel            = productViewModel;
     this.ProductID                   = productViewModel.ID;
     this.ProductName                 = productViewModel.Name;
     this.ProductPrice                = productViewModel.Price;
     productViewModel.ProductUpdated += () =>
     {
         ProductName  = productViewModel.Name;
         ProductPrice = productViewModel.Price;
     };
 }
Esempio n. 4
0
        /// <summary>
        /// Converting the <see cref="Product"/> object
        /// to <see cref="ProductRowViewer"/> object using ProductRowViewerViewModel
        /// </summary>
        /// <param name="product">The product to convert</param>
        private ProductRowViewerViewModel ConvertToProductRowViewer(Product product)
        {
            var viewModel = new ProductRowViewerViewModel
            {
                ID             = product.ID,
                Name           = product.Name,
                Category       = product.Category,
                StoredQuantity = product.QuantityInStock,
                Price          = product.Price,
                Description    = product.Description,
                Picture        = product.Image
            };

            viewModel.Deleted += DeleteItem;
            viewModel.Edited  += EditItem;
            viewModel.Printed += PrintItem;

            return(viewModel);
        }