コード例 #1
0
        public ActionResult Edit([Bind(Include = "Category_ID,Category_Name,Category_ImageName")] tbl_Categories tbl_Categories, HttpPostedFileBase CategoryEdit)
        {
            if (ModelState.IsValid)
            {
                if (CategoryEdit != null)
                {
                    string pathToSave = Server.MapPath(@"~/Content/Uploads/Categories/");

                    //tbl_Categories.Category_ImageName = file.FileName;

                    var replaceCategoryPhoto = new tbl_Categories()
                    {
                        Category_Name      = tbl_Categories.Category_Name,
                        Category_ImagePath = pathToSave
                    };

                    string NewFileName = String.Format("{0}.png", replaceCategoryPhoto.Category_Name);
                    replaceCategoryPhoto.Category_ImageName = NewFileName;
                    CategoryEdit.SaveAs(Path.Combine(pathToSave, NewFileName));
                }

                db.Entry(tbl_Categories).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tbl_Categories));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "City_ID,City_Name,AccountID")] tbl_Cities tbl_Cities)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_Cities).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AccountID = new SelectList(db.tbl_Accounts, "Account_ID", "Account_FirstName", tbl_Cities.AccountID);
     return(View(tbl_Cities));
 }