예제 #1
0
        public void ReturnToWarehouse(object sender, BakeryEventArgs args)
        {
            var bakeryProduct = _context.BakeryProducts.FirstOrDefault(bp => bp.Name == args.OrderedBakeryProduct.Name);

            if (bakeryProduct == null)
            {
                var newBakeryProduct = args.OrderedBakeryProduct.ToModel();
                _context.BakeryProducts.Add(newBakeryProduct);
            }
            else
            {
                bakeryProduct.Quantity += args.OrderedBakeryProduct.Quantity;
            }
            _context.SaveChanges();

            var bakeryProductView = BakeryProducts.FirstOrDefault(bp => bp.Name == args.OrderedBakeryProduct.Name);

            if (bakeryProductView == null)
            {
                BakeryProducts.Add(args.OrderedBakeryProduct);
            }
            else
            {
                bakeryProductView.Quantity += args.OrderedBakeryProduct.Quantity;
            }

            var orderedItem = OrderedProducts.FirstOrDefault(bp => bp.Name == args.OrderedBakeryProduct.Name);

            OrderedProducts.Remove(orderedItem);

            RaisePropertyChanged("BakeryProducts");
            RaisePropertyChanged("OrderedProducts");

            LoadProducts();
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            switch (state)
            {
            case 0:
                SelectedProducts = new ObservableCollection <Product>();
                foreach (var products in DataHolder.Products)
                {
                    if (products.Category == ((Product)((Button)sender).DataContext).Category)    //
                    {
                        SelectedProducts.Add(products);
                    }
                }
                ProductsMenuBack.IsEnabled = true;
                ProductsMenu.ItemsSource   = SelectedProducts;
                state++;
                break;

            case 1:
                ProductsMenu.ItemsSource   = Categories;
                ProductsMenuBack.IsEnabled = false;
                var prod  = (Product)((Button)sender).DataContext;
                var query = OrderedProducts.FirstOrDefault(op => op.Product == prod);
                if (query != null)
                {
                    query.Quantity++;
                }
                else
                {
                    OrderedProducts.Add(new OrderedProduct()
                    {
                        Product  = prod,
                        Quantity = 1,
                        Sliced   = false,
                        Slicable = prod.Category == "Pain" ? true : false
                    });
                }
                state--;
                break;
            }
        }