Beispiel #1
0
        public ShoppingCartViewModel(IContainerProvider provider, IEventAggregator eventAggregator, INavigationService navigationService)
        {
            EventAggregator = eventAggregator;
            Navigation      = navigationService;

            ShoppingCartService = provider.Resolve <IShoppingCartService>();

            ContinueShoppingCommand = new DelegateCommand(() => { }, () => CanContinue)
                                      .ObservesProperty(() => TotalPrice);

            CartContents = ShoppingCartService.CartContents;

            EventAggregator.GetEvent <AddToCartEvent>()
            .Subscribe((AddToCartEventArgs newEntry) => {
                var existing = ShoppingCartService.CartContents.FirstOrDefault(element => element.Sku == newEntry.Product.sku);

                if (existing == null)
                {
                    var newOne = new ProductViewModel(newEntry.Product, Navigation)
                    {
                        Quantity = newEntry.Quantity
                    };

                    CartContents.Add(newOne);
                }
                else
                {
                    existing.Quantity = newEntry.Quantity;
                }

                RaisePropertyChanged(nameof(TotalPrice));
                RaisePropertyChanged(nameof(CanContinue));
            });
        }
Beispiel #2
0
        private void AddToCartClicked(object obj)
        {
            Warning = "";
            Service selectedService = ServiceDisplayVM.SelectedService;

            if (ServiceDisplayVM.SelectedService == null)
            {
                Warning = "Please select a service.";
                MessageBox.Show("Please select a service");
                return;
            }

            Total += int.Parse(selectedService.Service_Cost);
            CartContents.Add(selectedService);
        }
        //adds selected pet and specified quantity
        // to user shopping cart.
        private void AddToCartClicked(object obj)
        {
            ContentControl cc = selectedControl.Content as ContentControl;
            ListBox        lb = cc.Content as ListBox;
            int            purchasedAmount = int.Parse(Quantity);

            if (selectedControl.Header.ToString() == "Pets")
            {
                Pets selectedPet = lb.SelectedItem as Pets;
                if (selectedPet.Stock - purchasedAmount >= 0)
                {
                    selectedPet.Stock          -= purchasedAmount;
                    selectedPet.PurchasedAmount = purchasedAmount;
                    CartContents.Add(selectedPet as object);
                    TotalCost += double.Parse(selectedPet.Price.ToString().Replace("$", "")) * purchasedAmount;
                }
                else
                {
                    MessageBox.Show("Not enough items in stock to purchase");
                }
            }
            else
            {
                Supplies selectedItem = lb.SelectedItem as Supplies;
                if (selectedItem.Stock - purchasedAmount >= 0)
                {
                    selectedItem.Stock          -= purchasedAmount;
                    selectedItem.PurchasedAmount = purchasedAmount;
                    CartContents.Add(selectedItem as object);
                    TotalCost += double.Parse(selectedItem.Price.ToString().Replace("$", "")) * purchasedAmount;
                }
                else
                {
                    MessageBox.Show("Not enough items in stock to purchase");
                }
            }
        }