public ActionResult ImagePreview(int?id) { tPhoto tPhoto = db.tPhoto.Find(id); byte[] img = tPhoto.fPh_PicFile; return(File(img, "image/jpeg")); }
public ActionResult tPhotoCreate(tPhoto tPhoto, int id) { tPhoto.fAl_ID = id; ViewBag.fAl_ID = new SelectList(db.tAlbum, "fAl_ID", "fAl_ID"); ViewBag.fMC_ID = new SelectList(db.tMessageCode, "fMC_ID", "fMC_ID"); return(View(tPhoto)); }
public ActionResult tPhotoDeleteConfirmed(int id) { tPhoto tPhoto = db.tPhoto.Find(id); db.tPhoto.Remove(tPhoto); db.SaveChanges(); return(RedirectToAction("Index", "Albums", new { area = "Albums" })); }
public ActionResult GetImage(int id) { tPhoto photo = db.tPhoto.Find(id); byte[] file = photo.fPh_PicFile; return(File(file, "image/jpeg")); }
public ActionResult tPhotoDelete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tPhoto tPhoto = db.tPhoto.Find(id); if (tPhoto == null) { return(HttpNotFound()); } return(View(tPhoto)); }
//public ActionResult MultiFileUploadDB() //{ // return View(); //} //[HttpPost] //public ActionResult MultiFileUploadDB(IEnumerable<HttpPostedFileBase> files, string text) //{ // if (ModelState.IsValid) // { // string message = null; // foreach (var file in files) // { // if (file != null && file.ContentLength > 0) // { // string fileName = Path.GetFileName(file.FileName); // int length = file.ContentLength; // byte[] buffer = new byte[length]; // file.InputStream.Read(buffer, 0, length); // var imgSize = file.ContentLength; // byte[] imgByte = new byte[imgSize]; // file.InputStream.Read(imgByte, 0, imgSize); // tPhoto tPhoto = new tPhoto() // { // fPh_Notes = text, // fPh_PicFile = imgByte, // fPh_Date = DateTime.Now, // }; // try // { // db.tPhoto.Add(tPhoto); // db.SaveChanges(); // message = "Name:" + fileName + ",<br>" + "Content Type:" + file.ContentType + ",<br>" + "Size:" + file.ContentLength + ",<br>" + "上傳成功。"; // TempData["Message"] = message; // } // catch (Exception ex) // { // TempData["Message"] = "儲存錯誤:" + ex.Message; // } // } // else // { // TempData["Message"] = "未選擇或空白檔案。"; // } // } // } // return View(); //} public ActionResult tPhotoEdit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tPhoto tPhoto = db.tPhoto.Find(id); if (tPhoto == null) { return(HttpNotFound()); } ViewBag.fAl_ID = new SelectList(db.tAlbum, "fAl_ID", "fAl_ID", tPhoto.fAl_ID); ViewBag.fMC_ID = new SelectList(db.tMessageCode, "fMC_ID", "fMC_ID", tPhoto.fMC_ID); return(View(tPhoto)); }
public ActionResult tPhotoCreate([Bind(Include = "fPh_ID,fPh_PicFile,fAl_ID,fPh_Date,fPh_Notes,fMC_ID")] tPhoto tPhoto, HttpPostedFileBase[] photoImage) { try { if (ModelState.IsValid) { if (photoImage != null && photoImage.Count() > 0) { foreach (var uploadFile in photoImage) { if (uploadFile.ContentLength > 0) { var imgSize = uploadFile.ContentLength; byte[] imgByte = new byte[imgSize]; uploadFile.InputStream.Read(imgByte, 0, imgSize); tMessageCode tMessageCode = new tMessageCode(); db.tMessageCode.Add(tMessageCode); db.SaveChanges(); tPhoto.fPh_Notes = ""; tPhoto.fPh_PicFile = imgByte; tPhoto.fPh_Date = DateTime.Now; tPhoto.fMC_ID = db.tMessageCode.AsEnumerable().Last().fMC_ID; db.tPhoto.Add(tPhoto); db.SaveChanges(); } } return(RedirectToAction("Photo", "Albums", new { area = "Albums", id = tPhoto.fAl_ID })); } } ViewBag.fAl_ID = new SelectList(db.tAlbum, "fAl_ID", "fAl_ID", tPhoto.fAl_ID); ViewBag.fMC_ID = new SelectList(db.tMessageCode, "fMC_ID", "fMC_ID", tPhoto.fMC_ID); return(View(tPhoto)); } catch (Exception ex) { return(RedirectToAction("Index", "Albums", new { area = "Albums" })); } }
public ActionResult tPhotoEdit([Bind(Include = "fPh_ID,fPh_PicFile,fAl_ID,fPh_Date,fPh_Notes,fMC_ID")] tPhoto tPhoto) { try { if (ModelState.IsValid) { db.Entry(tPhoto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Photo", "Albums", new { area = "Albums", id = tPhoto.fAl_ID })); } ViewBag.fAl_ID = new SelectList(db.tAlbum, "fAl_ID", "fAl_ID", tPhoto.fAl_ID); ViewBag.fMC_ID = new SelectList(db.tMessageCode, "fMC_ID", "fMC_ID", tPhoto.fMC_ID); return(View(tPhoto)); } catch (Exception ex) { throw ex; } }