public ActionResult Edit() { EntrepreneurAuth cred = check_clientRelation(); if (!cred.Valid) { return(Redirect(@"/User/Index")); } manageClient_Sessions(cred); Models.EntrepreneurEditViewModel entrepreneurAccount = new Models.EntrepreneurEditViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId()); return(View(entrepreneurAccount)); }
public ActionResult Edit(Models.EntrepreneurEditViewModel updateModel, HttpPostedFileBase update_Profile_Image) { EntrepreneurAuth cred = check_clientRelation(); if (!cred.Valid) { return(Redirect("/User/Index")); } try { // code to process a posted image file. byte[] picture_bytes = null; if (ModelState.IsValid) { if (update_Profile_Image != null) { if (update_Profile_Image.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 3; string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" }; if (!AllowedFileExtensions.Contains(update_Profile_Image.FileName.Substring(update_Profile_Image.FileName.LastIndexOf('.')))) { ModelState.AddModelError("profile_picture", "Please only use file types: " + string.Join(", ", AllowedFileExtensions)); } else if (update_Profile_Image.ContentLength > MaxContentLength) { ModelState.AddModelError("profile_picture", string.Format("Your file is too large, maximum file size is: {0} Bytes.", MaxContentLength)); } else { picture_bytes = new byte[update_Profile_Image.ContentLength]; update_Profile_Image.InputStream.Read(picture_bytes, 0, update_Profile_Image.ContentLength); } } } } Models.EntrepreneurEditViewModel authModel = new Models.EntrepreneurEditViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId()); authModel.Name = updateModel.Name; authModel.Profile_Public = updateModel.Profile_Public; authModel.Profile_Picture = picture_bytes; authModel.updateEntrepreneur(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(View()); } return(Redirect("/User/Index/")); }