예제 #1
0
        public void EditProduct(int index, string productName, int quantity, decimal price)
        {
            byte[]           binaryImage      = null;
            WpfMarketContext wpfMarketContext = new WpfMarketContext();

            foreach (Product product in wpfMarketContext.Products)
            {
                if (product.Name.Equals(productModels[index].Name))
                {
                    binaryImage = product.Image;
                    wpfMarketContext.Products.Attach(product);
                    wpfMarketContext.Products.Remove(product);
                }
            }

            Product newProduct = new Product()
            {
                Name     = productName,
                Quantity = quantity,
                Price    = price,
                Image    = binaryImage
            };

            wpfMarketContext.Products.Add(newProduct);
            wpfMarketContext.SaveChanges();

            productModels[index].Name     = productName;
            productModels[index].Quantity = quantity;
            productModels[index].Price    = price;
        }
예제 #2
0
        public void AddProduct(string productName, int quantity, decimal price, byte[] binaryImage)
        {
            WpfMarketContext wpfMarketContext = new WpfMarketContext();
            Product          product          = new Product()
            {
                Name     = productName,
                Quantity = quantity,
                Price    = price,
                Image    = binaryImage
            };

            wpfMarketContext.Products.Add(product);
            wpfMarketContext.SaveChanges();

            ProductModel productModel = new ProductModel(productName, quantity, price, binaryImage);

            productModels.Add(productModel);
        }
예제 #3
0
        public MarketViewModel()
        {
            name    = "WpfMarket - Swidzerland";
            phone   = "+41 066 686 52 59";
            email   = "*****@*****.**";
            address = "Hottingen, Zürich - Swidzrland";

            productModels = new ObservableCollection <ProductModel>();
            WpfMarketContext wpfMarketContext = new WpfMarketContext();

            foreach (Product product in wpfMarketContext.Products)
            {
                ProductModel productModel = new ProductModel(product.Name, product.Quantity, product.Price, product.Image);
                productModels.Add(productModel);
            }

            deleteProductCommand = new DelegateCommand(DeleteProduct, CanDeleteProduct);
        }
예제 #4
0
        public void DeleteProduct(object productModel)
        {
            if (productModel == null)
            {
                return;
            }
            WpfMarketContext wpfMarketContext = new WpfMarketContext();

            foreach (Product product in wpfMarketContext.Products)
            {
                if (product.Name.Equals((productModel as ProductModel).Name))
                {
                    wpfMarketContext.Products.Attach(product);
                    wpfMarketContext.Products.Remove(product);
                }
            }
            wpfMarketContext.SaveChanges();
            productModels.Remove(productModel as ProductModel);
        }