public ActionResult Added(galleryClass galleryClass,HttpPostedFileBase txt_file) { if (!CheckMemberlogin) { return RedirectToAction("login", "admin"); } else { leftModel(); galleryClass.root = 0; galleryClass.wdate = DateTime.Now; galleryClass.udate = DateTime.Now; galleryClass.isdel = 0; //檢查是否有選擇檔案 if (txt_file != null) { //檢查檔案大小要限制也可以在這裡做 if (txt_file.ContentLength > 0) { if (Directory.Exists(Server.MapPath(path))) { //資料夾存在 } else { //新增資料夾 Directory.CreateDirectory(Server.MapPath(path)); } string savedName = Path.Combine(Server.MapPath(path), DateTime.Now.ToString("yyyyMMdd") + txt_file.FileName); txt_file.SaveAs(savedName); galleryClass.img = DateTime.Now.ToString("yyyyMMdd") + txt_file.FileName; } } else { galleryClass.img = "no_image.jpg"; } gacd.Create(galleryClass); return RedirectToAction("Add", new { m = Request.QueryString["m"] }); } }
public ActionResult MiddleAdded(galleryClass galleryClass) { if (!CheckMemberlogin) { return RedirectToAction("login"); } else { leftModel(); galleryClass.root = galleryClass.num; //proclass.rootType = 0; galleryClass.isdel = 0; galleryClass.img = ""; gacd.Create(galleryClass); return RedirectToAction("Add", new { m = Request.QueryString["m"] }); } }
public ActionResult Edited(int cl, galleryClass galleryClass, int root, int isdel, HttpPostedFileBase txt_file) { if (!CheckMemberlogin) { return RedirectToAction("login", "admin"); } else { leftModel(); galleryClass.root = root; galleryClass.udate = DateTime.Now; galleryClass.isdel = isdel; //檢查是否有選擇檔案 if (txt_file != null) { //檢查檔案大小要限制也可以在這裡做 if (txt_file.ContentLength > 0) { if (Directory.Exists(Server.MapPath(path))) { //資料夾存在 } else { //新增資料夾 Directory.CreateDirectory(Server.MapPath(path)); } string savedName = Path.Combine(Server.MapPath(path), DateTime.Now.ToString("yyyyMMdd") + txt_file.FileName); txt_file.SaveAs(savedName); galleryClass.img = DateTime.Now.ToString("yyyyMMdd") + txt_file.FileName; } } else { var data = gacd.Get().ToList().Where(a => a.num == galleryClass.num).SingleOrDefault(); galleryClass.img = data.img; } gacd.Update(galleryClass); return RedirectToAction("Edit", new { cl = cl }); } }