public ActionResult Manage([Bind(Exclude = "ProfileImage")] ProfileModels profile) { // Excludes ProfileImage from controller call so it doesn't crash. if (ModelState.IsValid) { // Backup the profile image before possible change string profileId = profile.Id; byte[] backupImageCopy = profileRepository.Get(profileId).ProfileImage; //Possible new profile image input byte[] imageData = null; if (Request.Files["ProfileImage"].ContentLength >= 1) { HttpPostedFileBase poImgFile = Request.Files["ProfileImage"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { //This is the byte-array we set as the ProfileImage property on the profile. imageData = binary.ReadBytes(poImgFile.ContentLength); } } if (imageData != null) // If there is a new file input { profile.ProfileImage = imageData; } else // If there is not a new file input { profile.ProfileImage = backupImageCopy; // To make sure "null" is not submitted into the database } profileRepository.Edit(profile); profileRepository.Save(); return(RedirectToAction("Index")); } return(RedirectToAction("Manage")); }
public static void UpdateCareerPath(UserViewModel user, string path) { var profile = GetProfile(user.ProfileId.Value); profile.careerPath = path; Repository.Edit(profile); }