public ActionResult Edit([Bind(Include = "ActorId,ActorFirstName,ActorLastName,Address,City,State,ZipCode,PhoneNumber,AgencyID,ActorPhoto,SpecialNotes,DateAdded,IsActive")] Actor actor, HttpPostedFileBase actorheadshot) { if (ModelState.IsValid) { #region Image Upload if (actorheadshot != null) { /**/ string imgName = actorheadshot.FileName; /*1*/ string ext = imgName.Substring(imgName.LastIndexOf('.')); /*2*/ string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" }; /*3*/ if (goodExts.Contains(ext.ToLower()) && (actorheadshot.ContentLength <= 4193404)) { /*4*/ imgName = Guid.NewGuid() + ext.ToLower(); //commented this out and followed this other project file //actorheadshot.SaveAs(Server.MapPath("~/Content/actorheadshots/" + imgName)); #region Resize Image /*5*/ string savePath = Server.MapPath("~/Content/actorheadshots/"); //taking the contents of this file and creating a stream of bytes, http file base type is becoming a stream of bytes into a type of image. this conversion has to take place for us to be able to resize the image /*6*/ Image convertedImage = Image.FromStream(actorheadshot.InputStream); int maxImageSize = 500; int maxThumbSize = 100; //if you allowed image uploads for magazine and books - you would need to repeat that code - that's why the image service code is in an imageservice area /*7*/ UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize); UploadUtility.Delete(savePath, actor.ActorPhoto); actor.ActorPhoto = imgName; //saves image onto server - but doesn't update db need to make sure to update what is stored in the db #endregion } else { imgName = "nouserimg.png"; } actor.ActorPhoto = imgName; } #endregion db.Entry(actor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AgencyID = new SelectList(db.UserDetails, "UserID", "FirstName", actor.AgencyID); return(View(actor)); }
public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,AgencyName,UserPhoto,UserNotes,DateFounded")] UserDetail userDetail, HttpPostedFileBase agencyphoto) { if (ModelState.IsValid) { if (agencyphoto != null) { string imgName = agencyphoto.FileName; string ext = imgName.Substring(imgName.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" }; if (goodExts.Contains(ext.ToLower()) && (agencyphoto.ContentLength <= 4193404)) { imgName = Guid.NewGuid() + ext.ToLower(); string savePath = Server.MapPath("~/Content/agencylogo/"); Image convertedImage = Image.FromStream(agencyphoto.InputStream); int maxImageSize = 500; int maxThumbSize = 100; UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize); //UploadUtility.Delete(savePath, userDetail.UserPhoto); userDetail.UserPhoto = imgName; } else { imgName = "nouserimg.png"; } userDetail.UserPhoto = imgName; } db.Entry(userDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userDetail)); }
public ActionResult Edit([Bind(Include = "AuditionID,ActorId,LocationId,AuditionDate")] Reservation reservation) { if (ModelState.IsValid) { db.Entry(reservation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ActorId = new SelectList(db.Actors, "ActorId", "ActorFullName", reservation.ActorId); ViewBag.LocationId = new SelectList(db.AuditionLocations, "LocationID", "FullAuditionLocation", reservation.LocationId); return(View(reservation)); }