Ejemplo n.º 1
0
 public bool commitInsert(Product prod)
 {
     using (objProd)
     {
         objProd.Products.InsertOnSubmit(prod);
         //commit insert with db
         objProd.SubmitChanges();
         return true;
     }
 }
 public ActionResult ProductDelete(int ProductId, Product prod)
 {
     //Selected product will be deleted from the database
     try
     {
         objProd.commitDelete(ProductId);
         return RedirectToAction("ProductIndex");
     }
     catch
     {
         return View();
     }
 }
 partial void DeleteProduct(Product instance);
 partial void UpdateProduct(Product instance);
 partial void InsertProduct(Product instance);
        public ActionResult ProductUpdate(int ProductId, Product prod, HttpPostedFileBase file)
        {
            //Will check all the data regarding their validation , and if they were valid ,they are updated into database and then redirecting to the index view .
            /*this is for image upload*/
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Content/images/giftshop/")
                                                          + file.FileName);
                    prod.Image = file.FileName;
                }
                objProd.commitUpdate(ProductId, prod.Name, prod.Description, prod.UnitPrice, prod.Image, prod.Stock);
                return RedirectToAction("ProductIndex");
            }

            return View();
        }
        public ActionResult ProductInsert(Product prod, HttpPostedFileBase file)
        {
            //Will check all the data regarding their validation , and if they were valid ,they are inserted into database and then redirecting to the index view .
            /*this is for image upload*/
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Content/images/giftshop/")
                                                          + file.FileName);
                    prod.Image = file.FileName;
                }
                objProd.commitInsert(prod);
                return RedirectToAction("ProductIndex");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    objProd.commitInsert(prod);
                    return RedirectToAction("ProductIndex");
                }
                catch
                {
                    return View(prod);
                }
            }
            return View(prod);
        }