Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            _db = new ProductsGH();
            Products product = _db.Products.Find(id);

            _db.Products.Remove(product);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description, URL,Value")] Products product)
 {
     _db = new ProductsGH();
     if (ModelState.IsValid)
     {
         _db.Entry(product).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,URL,Value")] Products product)
        {
            _db = new ProductsGH();
            if (ModelState.IsValid)
            {
                if (_db.Products.FirstOrDefault() == null)
                {
                    product.ID = 0; //First Element in BD
                }
                else
                {
                    int maxId = _db.Products.Max(prod => prod.ID);
                    product.ID = maxId + 1;
                }
                _db.Products.Add(product);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }