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 Create([Bind(Include = "OwnerAssetId,CarName,OwnerId,CarPhoto,SpecialNotes,IsActive,DateAdded")] Car car, HttpPostedFileBase CarPhoto) { #region File Upload if (ModelState.IsValid) { //Use default image if none is provided. string imgName = "GenericCar.jpg"; if (CarPhoto != null) //HttpPostedFileBase added to the action != null { //Get image and return to variable. imgName = CarPhoto.FileName; //Declare and assign ext variable. string ext = imgName.Substring(imgName.LastIndexOf('.')); //Declare a list of valid extensions. string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" }; //Check the ext variable (toLower()) against the valid list. if (goodExts.Contains(ext.ToLower()) && (CarPhoto.ContentLength <= 4194304))//Max 4MB value allowed by ASP.net { //If it is in the list using a guid imgName = Guid.NewGuid() + ext; //save to the webserver CarPhoto.SaveAs(Server.MapPath("~/Content/assets/img/" + imgName)); //Create variables to resize image. string savePath = Server.MapPath("~/Content/assets/img/"); Image convertedImage = Image.FromStream(CarPhoto.InputStream); int maxImgSize = 500; int maxThumbSize = 100; UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImgSize, maxThumbSize); } else { imgName = "GenericCar.jpg"; } //No matter what, add imgName to the object. car.CarPhoto = imgName; } } #endregion if (ModelState.IsValid) { db.Cars.Add(car); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnerId = new SelectList(db.UserDetails, "UserId", "FirstName", car.OwnerId); return(View(car)); }
public ActionResult Edit([Bind(Include = "OwnerAssetId,CarName,OwnerId,CarPhoto,SpecialNotes,IsActive,DateAdded")] Car car, HttpPostedFileBase CarPhoto) { #region File Upload if (CarPhoto != null)//HttpPostedFileBase added to the action != null { //Get image and assign to variable string imgName = CarPhoto.FileName; //Declare and assign ext value string ext = imgName.Substring(imgName.LastIndexOf('.')); //Declare a list of valid extensions. string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" }; //Check the ext value (toLower()) against the valid list if (goodExts.Contains(ext.ToLower()) && (CarPhoto.ContentLength <= 4194304))//4MB max allowed by ASP.NET { //If it is in the list rename using a guid imgName = Guid.NewGuid() + ext; //Save to the webserver CarPhoto.SaveAs(Server.MapPath("~/Content/assets/img/" + imgName)); //Create variables to resize image. string savePath = Server.MapPath("~/Content/assets/img/"); Image convertedImage = Image.FromStream(CarPhoto.InputStream); int maxImgSize = 500; int maxThumbSize = 100; UploadUtility.ResizeImage(savePath, imgName, convertedImage, maxImgSize, maxThumbSize); //Make sure you are not deleting your default image. if (car.CarPhoto != null && car.CarPhoto != "GenericCar.jpg") { //Remove the original file string path = Server.MapPath("~/Content/assets/img/"); UploadUtility.Delete(path, car.CarPhoto); } //Only save if image meets criteria imageName to the object. car.CarPhoto = imgName; } } #endregion if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnerId = new SelectList(db.UserDetails, "UserId", "FirstName", car.OwnerId); return(View(car)); }
public ActionResult Edit([Bind(Include = "HomeId,HomeName,Address,City,State,ZipCode,OwnderId,HomePhoto,SpecialNotes,IsActive,DateAdded")] Homes homes, HttpPostedFileBase homePhoto) { if (ModelState.IsValid) { #region File Upload if (homePhoto != null) { string file = homePhoto.FileName; //we need to make sure they are actually uploading an appropriate file type string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; //check that the uploaded file is in our list of good file extensions if (goodExts.Contains(ext)) { //if valid ext, check file size <= 4mb (max by default from ASP.net) if (homePhoto.ContentLength <= 52428800) // specifying in bytes how big file can be { //create a new file name using a guid - a lot of users probably have images with the same names so we change it from what the user had to a guid Globally Unique Identifier file = Guid.NewGuid() + ext; #region Resize Image string savePath = Server.MapPath("~/Content/assets/img/Uploads/"); //taking the contents of this file and creatign a stream of bytes, http file base type is becmonig a stream of bytes into a type of image. this conversion has to take place for us to be able to resize the image Image convertedImage = Image.FromStream(homePhoto.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 UploadUtility.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); //saves image onto server - but doesn't update db need to make sure to update what is stored in the db #endregion if (homes.HomePhoto != null && homes.HomePhoto != "noimage.png") { string path = Server.MapPath("~/Content/assets/img/Uploads/"); UploadUtility.Delete(path, homes.HomePhoto); } } } homes.HomePhoto = file; } #endregion db.Entry(homes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OwnderId = new SelectList(db.UserDetails, "UserId", "CompanyName", homes.OwnderId); return(View(homes)); }
public ActionResult Create([Bind(Include = "PhotoID,Title,PhotoUrl,FilterID,OwnerAssetID")] Photo photo, HttpPostedFileBase myImg) { if (ModelState.IsValid) { #region PhotoUpload string imageName = "noImage.png"; if (myImg != null) { //Get File Extension - alternative to using a Substring () and Indexof() string imgExt = System.IO.Path.GetExtension(myImg.FileName); //list of allowed extentions string[] allowedExtentions = { ".png", ".gif", ".jpg", ".jpeg" }; if (allowedExtentions.Contains(imgExt.ToLower()) && (myImg.ContentLength <= 4194304)) { //using GUid for saved file name imageName = Guid.NewGuid() + imgExt; //creat some variables to pass to the resize image method //Signature to resize Image string savePath = Server.MapPath("~/Content/assets/img/portfolio/"); Image convertedImage = Image.FromStream(myImg.InputStream); int maxImgSize = 1200; int maxThumbSize = 100; //calling this method will use the variables created above will save the full size image and thumbnail img to your server. UploadUtility.ResizeImage(savePath, imageName, convertedImage, maxImgSize, maxThumbSize); ViewBag.PhotoMessage = "Photo Upload Complete."; } else { imageName = "noImage.png"; } photo.PhotoUrl = imageName; } #endregion db.Photos.Add(photo); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FilterID = new SelectList(db.Filters, "FilterID", "FilterName", photo.FilterID); ViewBag.OwnerAssetID = new SelectList(db.OwnerAssets, "OwnerAssetID", "AssetCallName", photo.OwnerAssetID); return(View(photo)); }
public ActionResult Create([Bind(Include = "OwnerAssetID,AssetRegisteredName,AssetCallName,AssetSpecies,AssetBreed,AssetAge,AssetSize,AssetTrainerCertified,UserID,AssetPhoto,SpecialNotes,IsActive,DateAdded,DescriptiveColorProfile")] OwnerAsset ownerAsset, HttpPostedFileBase myImg) { if (ModelState.IsValid) { #region PhotoUpload string imageName = "noImage.png"; if (myImg != null) { //Get File Extension - alternative to using a Substring () and Indexof() string imgExt = System.IO.Path.GetExtension(myImg.FileName); //list of allowed extentions string[] allowedExtentions = { ".png", ".gif", ".jpg", ".jpeg" }; if (allowedExtentions.Contains(imgExt.ToLower()) && (myImg.ContentLength <= 4194304)) { //using GUid for saved file name imageName = Guid.NewGuid() + imgExt; //creat some variables to pass to the resize image method //Signature to resize Image string savePath = Server.MapPath("~/Content/assets/Image/"); Image convertedImage = Image.FromStream(myImg.InputStream); int maxImgSize = 1200; int maxThumbSize = 100; //calling this method will use the variables created above will save the full size image and thumbnail img to your server. UploadUtility.ResizeImage(savePath, imageName, convertedImage, maxImgSize, maxThumbSize); ViewBag.PhotoMessage = "Photo Upload Complete."; } else { imageName = "noImage.png"; } ownerAsset.AssetPhoto = imageName; } #endregion db.OwnerAssets.Add(ownerAsset); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.OwnerInformations, "UserID", "FullName", ownerAsset.UserID); return(View(ownerAsset)); }
public ActionResult Edit([Bind(Include = "CourseID,CourseName,CourseDescription,CourseImage,IsActive")] Course course, HttpPostedFileBase courseImage) { if (ModelState.IsValid) { #region File Upload if (courseImage != null) { string file = courseImage.FileName; string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; //check that the uploaded file ext is in our list of good file extensions if (goodExts.Contains(ext)) { //if valid ext, check file size <= 4mb (max by default from ASP.NET) if (courseImage.ContentLength <= 4194304) { //create a new file name using a guid //file = Guid.NewGuid() + ext; #region Resize Image string savePath = Server.MapPath("~/Content/images/courses/"); Image convertedImage = Image.FromStream(courseImage.InputStream); int maxImageSize = 800; int maxThumbSize = 350; UploadUtility.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); #endregion if (course.CourseImage != null && course.CourseImage != "NoImage.png") { string path = Server.MapPath("~/Content/images/courses/"); UploadUtility.Delete(path, course.CourseImage); } } } course.CourseImage = file; } #endregion db.Entry(course).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase agencyphoto) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { string imgName = "~/Content/actorheadshots/nouserimg.png"; if (agencyphoto != null) { 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); } else { imgName = "nouserimg.png"; } } // Added Custom User Details #region Custom User Details UserDetail newUserDetails = new UserDetail(); newUserDetails.UserID = user.Id; newUserDetails.FirstName = model.FirstName; newUserDetails.LastName = model.LastName; newUserDetails.AgencyName = model.AgencyName; newUserDetails.UserPhoto = model.UserPhoto; newUserDetails.UserNotes = model.UserNotes; newUserDetails.DateFounded = model.DateFounded; newUserDetails.UserPhoto = imgName; AuditionsEntities db = new AuditionsEntities(); db.UserDetails.Add(newUserDetails); db.SaveChanges(); UserManager.AddToRole(user.Id, "Agency"); #endregion var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); ViewBag.Link = callbackUrl; return(View("RegisterSuccess")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase userPhoto) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { #region File Upload string file = "noimage.png"; //for this to work in our image files there is a NoImage.png file if (userPhoto != null) { file = userPhoto.FileName; //we need to make sure they are actually uploading an appropriate file type string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; //check that the uploaded file is in our list of good file extensions if (goodExts.Contains(ext)) { //if valid ext, check file size <= 4mb (max by default from ASP.net) if (userPhoto.ContentLength <= 4194304) // specifying in bytes how big file can be { //create a new file name using a guid - a lot of users probably have images with the same names so we change it from what the user had to a guid Globally Unique Identifier file = Guid.NewGuid() + ext; #region Resize Image string savePath = Server.MapPath("~/Content/assets/img/Uploads/"); //taking the contents of this file and creatign a stream of bytes, http file base type is becmonig a stream of bytes into a type of image. this conversion has to take place for us to be able to resize the image Image convertedImage = Image.FromStream(userPhoto.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 UploadUtility.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); //saves image onto server - but doesn't update db need to make sure to update what is stored in the db #endregion } } } #endregion #region assign UserDetails during registration UserDetails newUserDeets = new UserDetails(); newUserDeets.UserId = user.Id; //pulling id from aspnetusers tables newUserDeets.FirstName = model.FirstName; //model bc model is what is being pass in above in registermodelview newUserDeets.LastName = model.LastName; newUserDeets.CompanyName = model.CompanyName; newUserDeets.UserPhoto = file; //now save info to the database FinalProjectEntities db = new FinalProjectEntities(); db.UserDetails.Add(newUserDeets); db.SaveChanges(); #endregion UserManager.AddToRole(user.Id, "Client"); return(View("Login")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create([Bind(Include = "LocationID,LocationName,Address,City,State,ZipCode,AuditionLimit,AuditionPhoto,AuditionDetails,AuditionDate,IsActive,LManagerID")] AuditionLocation auditionLocation, HttpPostedFileBase alphoto) { //ViewBag.LManagerID = new SelectList(db.UserDetails, "UserID", "FirstName", auditionLocation.LManagerID); string currentUserID = User.Identity.GetUserId(); auditionLocation.LManagerID = currentUserID; if (ModelState.IsValid) { #region Image Upload string imgName = "nouserimg.png"; if (alphoto != null) { /**/ imgName = alphoto.FileName; /*1*/ string ext = imgName.Substring(imgName.LastIndexOf('.')); /*2*/ string[] goodExts = { ".jpeg", ".jpg", ".gif", ".png" }; /*3*/ if (goodExts.Contains(ext.ToLower()) && (alphoto.ContentLength <= 4193404)) { /*4*/ imgName = Guid.NewGuid() + ext.ToLower(); //actorheadshot.SaveAs(Server.MapPath("~/Content/actorheadshots/" + imgName)); #region Resize Image /*5*/ string savePath = Server.MapPath("~/Content/auditionlocations/"); //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(alphoto.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); //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"; } } auditionLocation.AuditionPhoto = imgName; #endregion db.AuditionLocations.Add(auditionLocation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LManagerID = new SelectList(db.UserDetails, "UserID", "AgentsFullName", auditionLocation.LManagerID); return(View(auditionLocation)); }