Example #1
0
        public ActionResult Edit([Bind(Include = "ProductID,Title,ShortDescription,Text,Price,ImageName,CreateDate")] Products products, List <int> selectedGroups, HttpPostedFileBase imageProduct, string tags)
        {
            if (ModelState.IsValid)
            {
                if (imageProduct != null && imageProduct.IsImage())
                {
                    if (products.ImageName != "images.jpg")
                    {
                        System.IO.File.Delete(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                        System.IO.File.Delete(Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                    }

                    products.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName);
                    imageProduct.SaveAs(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Images/ProductImages/" + products.ImageName),
                               Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                }
                db.Entry(products).State = EntityState.Modified;


                db.Product_Tags.Where(t => t.ProductID == products.ProductID).ToList().ForEach(t => db.Product_Tags.Remove(t));
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tag = tags.Split(',');
                    foreach (string t in tag)
                    {
                        db.Product_Tags.Add(new Product_Tags()
                        {
                            ProductID = products.ProductID,
                            Tag       = t.Trim()
                        });
                    }
                }


                db.Prodct_Selected_Groups.Where(g => g.ProductID == products.ProductID).ToList().ForEach(g => db.Prodct_Selected_Groups.Remove(g));
                if (selectedGroups != null && selectedGroups.Any())
                {
                    foreach (int selectedGroup in selectedGroups)
                    {
                        db.Prodct_Selected_Groups.Add(new Prodct_Selected_Groups()
                        {
                            ProductID = products.ProductID,
                            GroupID   = selectedGroup
                        });
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SelectedGroups = selectedGroups;
            ViewBag.Groups         = db.Product_Groups.ToList();
            ViewBag.Tags           = tags;
            return(View(products));
        }
 public ActionResult Edit([Bind(Include = "ProductID,Title,ShortDescription,Text,Price,ImageName,CreateDate")] Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(products));
 }
 public ActionResult Edit([Bind(Include = "FeatureID,FeatureTitle")] Features features)
 {
     if (ModelState.IsValid)
     {
         db.Entry(features).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(features));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "GroupID,GroupTitle,ParentID")] Product_Groups product_Groups)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Groups).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ParentID = new SelectList(db.Product_Groups, "GroupID", "GroupTitle", product_Groups.ParentID);
     return(View(product_Groups));
 }
Example #5
0
 public ActionResult Edit([Bind(Include = "UserID,RoleID,UserName,Email,Password,ActiveCode,IsActive,RegisterDate")] Users users)
 {
     if (ModelState.IsValid)
     {
         db.Entry(users).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "RoleTitle", users.RoleID);
     return(View(users));
 }
Example #6
0
 public ActionResult Edit([Bind(Include = "GroupID,GroupTitle,ParentID")] Product_Groups product_Groups)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Groups).State = EntityState.Modified;
         db.SaveChanges();
         return(PartialView("ListGroups", db.Product_Groups.Where(g => g.ParentID == null)));
     }
     ViewBag.ParentID = new SelectList(db.Product_Groups, "GroupID", "GroupTitle", product_Groups.ParentID);
     return(View(product_Groups));
 }
        public ActionResult Edit([Bind(Include = "SlideID,Title,ImageName,StartDate,EndDate,IsActive,Url")] Slider slider, HttpPostedFileBase imgUp)
        {
            if (ModelState.IsValid)
            {
                if (imgUp != null)
                {
                    System.IO.File.Delete(Server.MapPath("/Images/Slider/" + slider.ImageName));
                    slider.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(imgUp.FileName);
                    imgUp.SaveAs(Server.MapPath("/Images/Slider/" + slider.ImageName));
                }
                db.Entry(slider).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(slider));
        }