Exemple #1
0
        public ActionResult Index(FormCollection fc, HttpPostedFileBase file)
        {
            PnpProducts tbl = new PnpProducts();
            var         allowedExtensions = new[] {
                ".Jpg", ".png", ".jpg", "jpeg"
            };

            tbl.ProductName  = fc["productName"].ToString();
            tbl.ProductImage = file.ToString(); //getting complete url
            //tbl.Name = fc["Name"].ToString();

            var fileName = Path.GetFileName(file.FileName);                 //getting only file name(ex-ganesh.jpg)
            var ext      = Path.GetExtension(file.FileName);                //getting the extension(ex-.jpg)

            if (allowedExtensions.Contains(ext))                            //check what type of extension
            {
                string name   = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension
                string myfile = name + "_" + tbl.ProductID + ext;           //appending the name with id
                // store the file inside ~/project folder(Img)
                var path = Path.Combine(Server.MapPath("~/Img"), myfile);
                tbl.ProductImage = path;
                db.Products.Add(tbl);
                db.SaveChanges();
                file.SaveAs(path);
            }
            else
            {
                ViewBag.message = "Please choose only Image file";
            }
            return(View());
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            PnpProducts products = db.Products.Find(id);

            db.Products.Remove(products);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "productID,productName,productImage,productDropPercent,productDesc,productDateEndPromo,productPrice")] PnpProducts products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(products));
 }
Exemple #4
0
        public ActionResult Create([Bind(Include = "productID,productName,productImage,productDropPercent,productDesc,productDateEndPromo,productPrice")] PnpProducts products)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(products);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(products));
        }
Exemple #5
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PnpProducts products = db.Products.Find(id);

            if (products == null)
            {
                return(HttpNotFound());
            }
            return(View(products));
        }