public ActionResult HandleProfileImageForm(ProfileImageForm profileImageForm) { FormResponse formResponse = new FormResponse(); if (this.ModelState.IsValid) { formResponse.Success = true; IPartier partier = this.Members.GetCurrentPartier(); if (profileImageForm.ProfileImage != null && profileImageForm.ProfileImage.ContentLength > 0 && profileImageForm.ProfileImage.InputStream.IsImage()) { ProfileImage profileImage = partier.ProfileImage; string url = string.Empty; if (profileImage == null) { // create new profile image profileImage = ProfileImages.CreateProfileImage(profileImageForm.ProfileImage); // get the new url url = profileImage.Url; // update pointer on partier partier.ProfileImage = profileImage; } else { // update existing profile image url = profileImage.UploadImage(profileImageForm.ProfileImage); } formResponse.Message = JsonConvert.SerializeObject(new { id = profileImage.Id, url = url }); //TODO:S3URL } else // remove reference to image { // this will cause the file deletion partier.ProfileImage = null; } } else { formResponse.Errors = this.ModelState.GetErrors(); } return(Json(formResponse, "text/plain")); }