public ActionResult ChangeProfileImage(string tkn) { var changeProfileImage = new ChangeProfileImageViewModel(); changeProfileImage.TokenKey = tkn; return(PartialView("_ChangeProfileImage", changeProfileImage)); }
public async Task <IActionResult> ChangeProfileImage(ChangeProfileImageViewModel model) { if (ModelState.IsValid) { var user = await GetCurrentUserAsync(); if (user != null) { using (var fileStream = model.ImagePath.OpenReadStream()) { var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=mindsage;AccountKey=Xhaa5/DoM4usU0teA7pvQr/X7qo6g+6Vx+OGIvvzJb2obg6kpwH4dP5AWX0YKGuXxa+tNAQivwRuKYGphaWcEg==;BlobEndpoint=https://mindsage.blob.core.windows.net/"); var blobClient = storageAccount.CreateCloudBlobClient(); const string ContainerName = "userprofileimage"; var container = blobClient.GetContainerReference(ContainerName); await container.CreateIfNotExistsAsync(); var blob = container.GetBlockBlobReference(Guid.NewGuid().ToString()); blob.Properties.ContentType = model.ImagePath.ContentType; await blob.UploadFromStreamAsync(fileStream); var fileUrl = blob.Uri.AbsolutePath; // TODO: Update user profile image } var redirectURL = string.Format("/My#/app/course/{0}/setting", model.ClassRoom); return(Redirect(redirectURL)); } } return(View(model)); }
public IActionResult ChangeProfileImage(string id) { var model = new ChangeProfileImageViewModel { ClassRoom = id }; return(View(model)); }
public async Task <IActionResult> ChangeProfileImage(ChangeProfileImageViewModel model) { if (ModelState.IsValid) { var user = await GetCurrentUserAsync(); if (user != null) { try { var userprofile = _userprofileRepo.GetUserProfileById(User.Identity.Name); if (userprofile != null) { var uploadedURL = await _imageUploader.UploadUserProfile(User.Identity.Name, model.ImagePath.OpenReadStream(), model.ImagePath.ContentType); userprofile.ImageProfileUrl = uploadedURL; _userprofileRepo.UpsertUserProfile(userprofile); var process = _backgroundProcessQueue.EnqueueUpdateUserProfile(new Engines.UpdateUserProfileMessage { UserProfileId = User.Identity.Name, DisplayName = userprofile.Name, ProfileImageUrl = userprofile.ImageProfileUrl }); await Task.WhenAll(process); } var redirectURL = $"/my#!/app/course/{ model.ClassRoom }/setting"; return(Redirect(redirectURL)); } catch (Exception) { ViewBag.ErrorMessage = _errorMsgs.CanNotConnectToTheDatabase; return(View("Error")); } } } return(View(model)); }
public ActionResult ChangeProfileImage(ChangeProfileImageViewModel changeProfileImage) { string JsonStr = ""; bool isSuccess = true; string message = "Update Successful!"; if (ModelState.IsValid) { try { var user = _userBusiness.GetListWT(c => c.TokenKey == changeProfileImage.TokenKey).FirstOrDefault(); FileOperations.CreateDirectory(Server.MapPath("~/ProfileImage")); if (changeProfileImage.ProfileImageUpload != null) { string ext = Path.GetExtension(changeProfileImage.ProfileImageUpload.FileName).ToLower(); string filename = changeProfileImage.TokenKey + ext; string filePath = Server.MapPath("~/ProfileImage/") + filename; changeProfileImage.ProfileImageUpload.SaveAs(filePath); user.ProfileImage = filename; _userBusiness.Update(user); _unitOfWork.SaveChanges(); } } catch (Exception ex) { message = "Update Failed!!"; isSuccess = false; _unitOfWork.Dispose(); } } TempData["Success"] = message; TempData["isSuccess"] = isSuccess.ToString(); JsonStr = "{\"message\":\"" + message + "\",\"isSuccess\":\"" + isSuccess + "\"}"; return(Json(JsonStr, JsonRequestBehavior.AllowGet)); }