Example #1
0
        public async Task <IActionResult> UpdateProfile(UpdateProfileViewModel model, string Id)
        {
            var user = await _userManager.FindByIdAsync(Id);

            if (!ModelState.IsValid)
            {
                model.UserPhotoPath = user.UserPhotoPath;
                return(View(model));
            }
            _mapper.Map(model, user);
            var photoPath = (await _photoService.AddImage(model.ImageInfo));

            if (photoPath != null)
            {
                user.UserPhotoPath = photoPath;
            }
            var result = await _userManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    AddErrors(error.Description);
                }
                return(View(model));
            }
            return(RedirectToAction(nameof(ProfileController.ProfileInfo), new { Id }));
        }