Beispiel #1
0
        public ActionResult CreateProduct(Product pro, HttpPostedFileBase fPmain,
                                          HttpPostedFileBase fPmainthums)
        {
            pro.TinyDes = pro.TinyDes == null ? string.Empty : pro.TinyDes;
            pro.FullDes = pro.FullDes == null ? string.Empty : pro.FullDes;
            string spDirPath = Server.MapPath("~/Images/Imgs/sp");

            using (var db = new QLBHEntities())
            {
                db.Products.Add(pro);
                db.SaveChanges();
            }
            ServiceUpload.UploadImage(spDirPath, pro.ProID, fPmain, fPmainthums);
            return(RedirectToAction("GetProduct", new { id = pro.CatID }));
        }
Beispiel #2
0
 public ActionResult DeleteProduct(int proid, int pa)
 {
     using (var db = new QLBHEntities())
     {
         var p = db.Products.Where(item => item.ProID == proid).FirstOrDefault();
         if (p != null)
         {
             string spDirPath = Server.MapPath("~/Images/Imgs/sp");
             ServiceUpload.Remove(spDirPath, p.ProID);
             db.Products.Remove(p);
             db.SaveChanges();
         }
         return(RedirectToAction("GetProduct", new { id = p.CatID, page = pa }));
     }
 }
Beispiel #3
0
        public ActionResult UpdateProduct(Product pro, HttpPostedFileBase fPmain,
                                          HttpPostedFileBase fPmainthums)
        {
            using (var DB = new QLBHEntities())
            {
                Product proEdit = DB.Products.Where(item => item.ProID == pro.ProID)
                                  .FirstOrDefault();
                if (proEdit != null)
                {
                    string spDirPath = Server.MapPath("~/Images/Imgs/sp");
                    ServiceUpload.UploadImage(spDirPath, pro.ProID, fPmain, fPmainthums);
                    proEdit.ProName  = pro.ProName;
                    proEdit.Quantity = pro.Quantity;
                    proEdit.Price    = pro.Price;
                    proEdit.TinyDes  = pro.TinyDes;
                    proEdit.FullDes += pro.FullDes;

                    DB.SaveChanges();
                    DB.Entry(proEdit).State = EntityState.Modified;
                }
                ViewBag.Cat = DB.Categories.ToList();
                return(RedirectToAction("GetProduct", new { id = proEdit.CatID }));
            }
        }