Exemple #1
0
 protected override void Dispose(bool disposing)
 {
     _db = new ProductsGH();
     if (disposing)
     {
         _db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            _db = new ProductsGH();
            Products product = _db.Products.Find(id);

            _db.Products.Remove(product);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
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));
 }
Exemple #4
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            _db = new ProductsGH();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Products product = _db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            return(View(product));
        }
Exemple #5
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));
        }
Exemple #6
0
 // GET: Products
 public ActionResult Index()
 {
     _db = new ProductsGH();
     return(View(_db.Products.ToList()));
 }