コード例 #1
0
        public ProductsListViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(
                new System.Windows.DependencyObject())) return;

            try
            {
                var products = db.Products.ToList();
                Products = new ObservableCollection<Product>(products);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }

            _newProduct = new Product();
            _searchResults = new ObservableCollection<Product>();

            DeleteProductCommand = new RelayCommand<Product>(onDeleteProduct);
            UpdateProductCommand = new RelayCommand<Product>(onUpdateProduct);
            AddProductCommand = new RelayCommand<Product>(onAddProduct);
            FindProductsCommand = new RelayCommand<string>(onFindProducts);
        }
コード例 #2
0
        public void onDeleteProduct(Product prod)
        {
            if (prod != null)
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure you wish to delete this product?", "Confirm Delete", System.Windows.MessageBoxButton.YesNo);

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int productid = prod.productID;
                    Product prodToRemove = (Product)Products.Single(e => e.productID == productid);

                    db.Products.Remove(prodToRemove);
                    db.SaveChanges();
                    Products = UpdateProductsCollection(Products);
                }
            }
        }
コード例 #3
0
        public void onUpdateProduct(Product prod)
        {
            var product = prod;

            if (product != null)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                Products = UpdateProductsCollection(Products);

                MessageBoxResult msgBox = MessageBox.Show("Changes Saved", "Success");

            }
        }
コード例 #4
0
        public void onAddProduct(Product prod)
        {
            var newProduct = prod;

            if (newProduct != null)
            {
                db.Products.Add(newProduct);
                db.SaveChanges();
                Products = UpdateProductsCollection(Products);
                MessageBoxResult msgBox = MessageBox.Show("Product Added", "Success");
            }
        }