Ejemplo n.º 1
0
        public async Task <IActionResult> EditProfileImage(AjaxUserEditProfileImage model, CancellationToken cancellationToken)
        {
            AjaxResult result = new AjaxResult("Error");

            CustomUser user = await _userManager.FindByIdAsync(model.Id);

            if (user != null)
            {
                string uploads             = Path.Combine(_hostingEnvironment.WebRootPath, "images", "UserProfile");
                string OldProfileImagePath = $"{_hostingEnvironment.WebRootPath}\\images\\UserProfile\\{user.Avatar}";
                string strFilePath         = await fileHandler.UploadFileAsync(model.FormFile, uploads, cancellationToken, OldProfileImagePath);

                user.Avatar = strFilePath;
                IdentityResult Result = await _userManager.UpdateAsync(user);

                if (Result.Succeeded)
                {
                    result.Status               = "Success";
                    result.RedirectUrl          = "/User/Home/Index";
                    result.MessageWhenSuccessed = "تصویر پروفایل با موفقیت عوض شد";
                    return(new JsonResult(result));
                }
                else
                {
                    ModelState.AddModelStateError(Result.Errors.Select(c => c.Description));
                }
            }
            ModelState.AddModelError("", "کاربر یافت نشد");
            result.AddErrors(ModelState);
            return(new JsonResult(result));
        }
Ejemplo n.º 2
0
        public IActionResult EditProfileImage()
        {
            AjaxUserEditProfileImage model = new AjaxUserEditProfileImage
            {
                Id = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value
            };

            return(PartialView("EditUserProfileIamgePartialView", model));
        }