public ActionResult DeleteConfirmed(int id) { TSTPortfolioImage tSTPortfolioImage = db.TSTPortfolioImages.Find(id); db.TSTPortfolioImages.Remove(tSTPortfolioImage); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: TSTPortfolioImages/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TSTPortfolioImage tSTPortfolioImage = db.TSTPortfolioImages.Find(id); if (tSTPortfolioImage == null) { return(HttpNotFound()); } return(View(tSTPortfolioImage)); }
public ActionResult Edit([Bind(Include = "ImageID,Image")] TSTPortfolioImage tSTPortfolioImage, HttpPostedFileBase uploadImage) { if (ModelState.IsValid) { #region file upload edit if (uploadImage != null) { //got the file name string imageName = uploadImage.FileName; //extract the extension and store it string ext = imageName.Substring(imageName.LastIndexOf('.')); //check the file ext against valid file types string[] goodExts = new string[] { ".gif", ".jpg", ".png", ".jpeg" }; //as long as it is a valid if (goodExts.Contains(ext)) { imageName = Guid.NewGuid() + ext; uploadImage.SaveAs(Server.MapPath("~/Content/img/UploadedImages/" + imageName)); tSTPortfolioImage.Image = imageName; } } #endregion db.Entry(tSTPortfolioImage).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tSTPortfolioImage)); }
public ActionResult Create([Bind(Include = "ImageID,Image")] TSTPortfolioImage tSTPortfolioImage, HttpPostedFileBase uploadImage) { ////validation for file upload //int permittedSizeInBytes = 40000;//4mb //string permittedType = "image/jpeg, image/gif"; //if (Request.Files.Count > 0) //{ // var file = Request.Files[0]; // if (file != null && file.ContentLength > 0) // { // if (file.ContentLength < permittedSizeInBytes) // { // ViewBag.Message = "File cannot be more than 4MB"; // } // else // { // if (!permittedType.Split(",".ToCharArray()).Contains(file.ContentType)) // { // ViewBag.Message = "Invalid file type"; // } // else // { // var fileName = Path.GetFileName(file.FileName); // var path = Path.Combine(Server.MapPath("~/Content/img/UploadedImages/"), fileName); // file.SaveAs(path); // ViewBag.Message = "File uploaded successfully"; // } // } // } // else // { // ViewBag.Message = "File does not have any content"; // } // ViewBag.Message = "No files uploaded"; // return View(); //} if (ModelState.IsValid) { #region file upload create string imageName = "NoImage.png"; if (uploadImage != null) { imageName = uploadImage.FileName; //extract the extension and store it string ext = imageName.Substring(imageName.LastIndexOf('.')); //check the file ext against valid file types string[] goodExts = new string[] { ".gif", ".jpg", ".png", ".jpeg" }; //as long as it is a valid if (goodExts.Contains(ext)) { imageName = Guid.NewGuid() + ext; uploadImage.SaveAs(Server.MapPath("~/Content/img/UploadedImages/" + imageName)); } else { imageName = "NoImage.png"; } } tSTPortfolioImage.Image = imageName; #endregion db.TSTPortfolioImages.Add(tSTPortfolioImage); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tSTPortfolioImage)); }