Пример #1
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Пример #2
0
        public bool AddStock(string productCode, decimal quantity)
        {
            try
            {
                // Connect to the ProductsModel database
                using (ProductsModel database = new ProductsModel())
                {
                    // Find the ProductID for the specified product
                    int productID = (from p in database.Products where String.Compare(p.Code, productCode) == 0 select p.Id).First();

                    // Find the Stock object that matches the parameters passed
                    // in to the operation
                    Stock stock = database.Stocks.First(pi => pi.Id == productID);
                    stock.Quantity   = quantity;
                    stock.LastUpdate = DateTime.Now;

                    database.Stocks.Add(stock);

                    database.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
 public Product Create(Product product)
 {
     using (var context = new ProductsModel())
     {
         var newProduit = context.Products.Add(product);
         context.SaveChanges();
         return(newProduit);
     }
 }
Пример #4
0
 public void Update(int id, Product product)
 {
     using (var context = new ProductsModel())
     {
         var oldProduct = context.Products.Find(id);
         if (oldProduct == null)
         {
             throw new Exception("Le produit " + id + " n'existe pas");
         }
         oldProduct.Description = product.Description;
         oldProduct.Name        = product.Name;
         oldProduct.Price       = product.Price;
         context.SaveChanges();
     }
 }
Пример #5
0
        private void DelProduct_Click(object sender, EventArgs e)
        {
            if (dataProducts.SelectedRows.Count > 0)
            {
                DialogResult deluser = MessageBox.Show("Eliminar los datos del producto: " + dataProducts.CurrentRow.Cells[1].Value.ToString() + "? ", "Eliminar datos", MessageBoxButtons.YesNo);
                if (deluser == DialogResult.Yes)
                {
                    product.State     = EntityState.Deleted;
                    product.IdProdMod = Convert.ToInt32(dataProducts.CurrentRow.Cells[0].Value);

                    string result = product.SaveChanges();
                    MessageBox.Show(result);
                    ListProducts();
                }
            }
            else
            {
                MessageBox.Show("Seleccione el producto a eliminar");
            }
        }
Пример #6
0
        private void BtnsaveProduct_Click(object sender, EventArgs e)
        {
            product.ProdCodMod  = txtCodPro.Text;
            product.ProdNameMod = txtNamePro.Text;
            if (txtIdPro.Text == "")
            {
                product.State = EntityState.Added;
            }
            else
            {
                product.State = EntityState.Modified;
            }

            bool valid = new Helps.DataValidation(product).Validate();

            if (valid == true)
            {
                if (txtMayPro.Text == "")
                {
                    MessageBox.Show("Ingrese el precio al por mayor del producto");
                }
                else
                {
                    if (txtMenPro.Text == "")
                    {
                        MessageBox.Show("Ingrese el precio al por menor del producto");
                    }
                    else
                    {
                        product.ProdPrMayMod = float.Parse(txtMayPro.Text.Trim());
                        product.ProdPrMenMod = float.Parse(txtMenPro.Text.Trim());
                        product.ProdStockMod = Convert.ToInt32(txtStockPro.Text);

                        string result = product.SaveChanges();
                        MessageBox.Show(result);
                        Restart();
                        Close();
                    }
                }
            }
        }