public async Task <IActionResult> Update([FromForm] ApplicationUser obj, [FromForm] IFormFile fImage) { var response = new Response(); var responseEr = new ResponseError(); var currentUser = await _userStoreExtend.FindByIdAsync(obj.Id); if (fImage != null) { var physicalPath = new InsideImageResources().GeneratePhysicalPath(GetHostEnviroment(), FileType.Images, ModuleResources.Avatar); var virtualPath = new InsideImageResources().GenerateVirtualPath(FileType.Images, ModuleResources.Avatar); var _physicalPath = physicalPath.FriendlyPath("UserId" + obj.Id.ToString(), fImage, 1); var _virtualPath = virtualPath.FriendlyPath("UserId" + obj.Id.ToString(), fImage, 1); //FileHelper.ImageProcessing(fImage, _physicalPath, false); obj.Avatar = _virtualPath; } currentUser.Avatar = (obj.Avatar == null ? currentUser.Avatar : obj.Avatar); currentUser.FullName = (obj.FullName == null ? currentUser.FullName : obj.FullName); currentUser.PhoneNumber = (obj.PhoneNumber == null ? currentUser.PhoneNumber : obj.PhoneNumber); var result = await _userManager.UpdateAsync(currentUser); if (result.Succeeded) { var permissions = await _roleStoreExtend.ReadByUser(currentUser.Id); //Mapping var userInfo = _mapper.Map <UserInfo>(currentUser); userInfo.Permissions = permissions; string[] output = userInfo.FullName.Split(' '); foreach (string s in output) { userInfo.LetterAvatar += s[0]; } userInfo.Avatar = (userInfo.Avatar == null ? "" : GetUrlImage() + userInfo.Avatar); userInfo.PhoneNumber = (userInfo.PhoneNumber == null ? "" : userInfo.PhoneNumber); userInfo.LetterAvatar = userInfo.LetterAvatar.ToUpper(); response.response = userInfo; return(Ok(response)); } else { responseEr.status = "Cập nhật thông tin thất bại!"; return(Ok(responseEr)); } }
public AccountController( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IUserRepository userStoreExtend, IMapper mapper, IConfiguration config, IOptions <ImageResources> imageSize, IRoleRepository roleStoreExtend ) { _userManager = userManager; _userStoreExtend = userStoreExtend; _signInManager = signInManager; _mapper = mapper; _config = config; _imageSize = imageSize; _imageResources = new InsideImageResources(); _roleStoreExtend = roleStoreExtend; }
//private IOptions<FirebaseCloudMessage> _fcm; public AuthenticationController( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IUserRepository userStoreExtend, IRoleRepository roleStoreExtend, IMapper mapper, IOptions <ExternalProvider> externalProvider, IOptions <ImagePath> imagePath, IOptions <MailOpt> mailHelper, IGenericRepository generic ) { _mailHelper = mailHelper; _userManager = userManager; _signInManager = signInManager; _userStoreExtend = userStoreExtend; _roleStoreExtend = roleStoreExtend; _mapper = mapper; _externalProvider = externalProvider; _imagePath = imagePath; _imageResources = new InsideImageResources(); _generic = generic; }