예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product product = db.Products.Find(id);

            ImageFuctionality.DeleteImageFromServer(product.imgName, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath);

            db.Products.Remove(product);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Edit([Bind(Include = "ProductId,Name,Description,Price,Category,imgName,Count")] Product product, HttpPostedFileBase file, string imgName_old)
        {
            ViewBag.Categories = Utility.CategoriesSelectList();

            if (product.Category == "all")
            {
                ModelState.AddModelError("Category", "Chose product category");
            }

            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    product.imgName = ImageFuctionality.UploadImage(file, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath);
                    ImageFuctionality.DeleteImageFromServer(imgName_old, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath);
                }

                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }