Exemplo n.º 1
0
        private void ExecuteAddToCart(object sender)
        {
            Button  button  = sender as Button;
            Product product = (Product)button.DataContext;

            if (MainVM.ProductRepository.GetById(product.Id) != null)
            {
                Ordered ordered = new Ordered()
                {
                    Product = product, Amount = 1
                };
                Order order = MainVM.GetCreatedOrder();
                if (order == null)
                {
                    order = new Order()
                    {
                        Customer = MainVM.Customer, State = State.Created
                    };
                }
                order.Ordered.Add(ordered);
                button.Content   = "В корзине";
                button.IsEnabled = false;
            }
            else
            {
                MessageBox.Show("Товар не найден, пожалуйста, обновите страницу");
            }
        }