Exemple #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));
        }
Exemple #2
0
        /// <summary>
        /// Deletes the specified item from the list
        /// </summary>
        /// <param name="viewModel">The view model of the item to delete</param>
        protected override void DeleteItem(BaseRowViewerViewModel viewModel)
        {
            OrderRowViewerViewModel vm = viewModel as OrderRowViewerViewModel;

            // Delete from the items list
            Items.Remove(viewModel);
            CurrentCart.Remove(viewModel);
            vm.ProductViewModel.IsOutFromCart = true;
            for (int i = ((OrderRowViewerViewModel)viewModel).RowNumber - 1; i < Items.Count; i++)
            {
                ((OrderRowViewerViewModel)Items[i]).RowNumber--;
            }
            OnPropertyChanged(nameof(TotalPrice));
        }
Exemple #3
0
        /// <summary>
        /// Converting the <see cref="Order"/> object
        /// to <see cref="OrderRowViewer"/> object using <see cref="OrderRowViewerViewModel"/>
        /// </summary>
        /// <param name="orderLine">The order line to convert</param>
        private OrderRowViewerViewModel ConvertToOrderRowViewer(OrderLine orderLine)
        {
            var viewModel = new OrderRowViewerViewModel
                            (
                orderLine.RowNumber,
                orderLine.Order.ID,
                orderLine.Quantity.ToString(),
                orderLine.Discount.ToString(),
                orderLine.ProductName,
                orderLine.ProductPrice
                            );

            viewModel.CanDelete = false;

            return(viewModel);
        }