public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                var currentCustomer = db.Customers.FirstOrDefault(s => s.CustomerID == id);
                if (currentCustomer == null)
                {
                    return(HttpNotFound());
                }

                currentCustomer.Status          = false;
                db.Entry(currentCustomer).State = EntityState.Modified;
                db.SaveChanges();

                // your code for insert here
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            return(RedirectToAction("Index"));
        }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "Id,DivisionID,Name,ManagerID")] Division division)
 {
     if (ModelState.IsValid)
     {
         db.Entry(division).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(division));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,Message,Email,DateSent,Subject")] Conntact conntact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(conntact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(conntact));
 }
 public ActionResult Edit([Bind(Include = "CategoryID,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "StoreID,StoreName,Address,Phone")] Store store)
 {
     if (ModelState.IsValid)
     {
         db.Entry(store).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(store));
 }
 public ActionResult Edit([Bind(Include = "StoreID,ProductID,Quantity")] Stock stock)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stock).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", stock.ProductID);
     ViewBag.StoreID   = new SelectList(db.Stores, "StoreID", "StoreName", stock.StoreID);
     return(View(stock));
 }
        public ActionResult Edit([Bind(Include = "BrandID,Name,BrandImg")] Brand brand, HttpPostedFileBase BrandImg)
        {
            if (ModelState.IsValid)
            {
                string postedFileName = System.IO.Path.GetFileName(BrandImg.FileName);
                //Lưu hình đại diện về Server
                var path = Server.MapPath("/Assets/images/" + postedFileName);
                BrandImg.SaveAs(path);
                brand.BrandImg = "/Assets/images/" + postedFileName;

                db.Entry(brand).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(brand));
        }
        public ActionResult Edit([Bind(Include = "ProductID,Name,BrandID,CategoryID,Price,ProductImg, Description, Status")]
                                 Product product, HttpPostedFileBase ProductImg)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                string postedFileName = Path.GetFileName(ProductImg.FileName);
                var    path           = Server.MapPath("/Assets/images/" + postedFileName);
                ProductImg.SaveAs(path);
                product.ProductImg = "/Assets/images/" + postedFileName;

                product.Status          = true;
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.BrandID    = new SelectList(db.Brands, "BrandID", "Name", product.BrandID);
            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", product.CategoryID);
            return(View(product));
        }