public async Task <OperationResponse> UpdateAsync(UserInputDto dto) { dto.NotNull(nameof(dto)); var user = await _userManager.FindByIdAsync(dto.Id.ToString()); user = dto.MapTo(user); var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { return(result.ToOperationResponse()); } return(new OperationResponse("更新成功!!", OperationResponseType.Success)); }
public async Task <OperationResponse> CreateAsync(UserInputDto dto) { dto.NotNull(nameof(dto)); var passwordHash = dto.PasswordHash; var user = dto.MapTo <User>(); var result = passwordHash.IsNullOrEmpty() ? await _userManager.CreateAsync(user) : await _userManager.CreateAsync(user, passwordHash); if (!result.Succeeded) { return(result.ToOperationResponse()); } return(new OperationResponse("添加用户成功", OperationResponseType.Success)); }
//[NonGlobalAopTran] //[ValidationInterceptor] public async Task <OperationResponse> CreateAsync(UserInputDto dto) { dto.NotNull(nameof(dto)); var passwordHash = dto.PasswordHash; var user = dto.MapTo <User>(); return(await _unitOfWork.UseTranAsync(async() => { var result = passwordHash.IsNullOrEmpty() ? await _userManager.CreateAsync(user) : await _userManager.CreateAsync(user, passwordHash); if (!result.Succeeded) { return result.ToOperationResponse(); } if (dto.RoleIds.Any() == true) { return await this.SetUserRoles(user, dto.RoleIds); } return new OperationResponse("添加用户成功", OperationResponseType.Success); })); }
public async Task <OperationResponse> UpdateAsync(UserInputDto dto) { dto.NotNull(nameof(dto)); var user = await _userManager.FindByIdAsync(dto.Id.ToString()); user = dto.MapTo(user); return(await _unitOfWork.UseTranAsync(async() => { var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { return result.ToOperationResponse(); } if (dto.RoleIds?.Any() == true) { return await this.SetUserRoles(user, dto.RoleIds); } return new OperationResponse("更新成功!!", OperationResponseType.Success); })); }
public async Task <OperationResponse> InsertAsync(UserInputDto input) { input.NotNull(nameof(input)); var user = input.MapTo <UserEntity>(); var passwordHash = input.PasswordHash; var result = passwordHash.IsNullOrEmpty() ? await _userManager.CreateAsync(user) : await _userManager.CreateAsync(user, passwordHash); return(result.ToOperationResponse()); // return await _unitOfWork.UseTranAsync(async () => //{ // if (!result.Succeeded) // return result.ToOperationResponse(); // if (input.RoleIds?.Any() == true) // { // await _userRoleRepository.InsertAsync(input.RoleIds.Select(x => new UserRoleEntity // { // RoleId = x, // UserId = user.Id, // }).ToArray()); // } // return new OperationResponse(ResultMessage.InsertSuccess, OperationEnumType.Success); //}); }