/// <summary> /// 微信注册普通会员用户 /// </summary> /// <param name="userInPut">第三方类型</param> /// <returns></returns> public bool CreateUserByWxOpenId(UserInputDto userInPut) { User user = userInPut.MapTo <User>(); UserLogOn userLogOnEntity = new UserLogOn(); UserOpenIds userOpenIds = new UserOpenIds(); user.Id = user.CreatorUserId = GuidUtils.CreateNo(); user.Account = "Wx" + GuidUtils.CreateNo(); user.CreatorTime = userLogOnEntity.FirstVisitTime = DateTime.Now; user.IsAdministrator = false; user.EnabledMark = true; user.Description = "第三方注册"; user.IsMember = true; user.UnionId = userInPut.UnionId; user.ReferralUserId = userInPut.ReferralUserId; if (userInPut.NickName == "游客") { user.RoleId = _roleService.GetRole("guest").Id; } else { user.RoleId = _roleService.GetRole("usermember").Id; } userLogOnEntity.UserId = user.Id; userLogOnEntity.UserPassword = GuidUtils.NewGuidFormatN() + new Random().Next(100000, 999999).ToString(); userLogOnEntity.Language = userInPut.language; userOpenIds.OpenId = userInPut.OpenId; userOpenIds.OpenIdType = userInPut.OpenIdType; userOpenIds.UserId = user.Id; return(_userRepository.Insert(user, userLogOnEntity, userOpenIds)); }
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 IActionResult Mapper() { StringBuilder sb = new StringBuilder(); UserInputDto dto = new UserInputDto() { Id = 1, UserName = "******", NickName = "郭老板" }; sb.AppendLine($"UserInputDto:{dto.ToJsonString()}"); User user = dto.MapTo <User>(); sb.AppendLine($"User: {user.ToJsonString()}"); return(Content(sb.ToString())); }
public async Task UpsertUser(UserInputDto input) { try { await Task.Run(() => { var userInput = input.MapTo <User>(); if (input.Id == 0) { userInput.TenantId = AbpSession.TenantId; userInput.Password = new PasswordHasher().HashPassword(input.Password); userInput.IsEmailConfirmed = true; //CheckErrors(await UserManager.CreateAsync(userInput)); } else { //var user = await _userRepository.GetAll().AsNoTracking().SingleAsync(u => u.Id == input.Id); /* * user.UserName = input.UserName; * user.Name = input.Name; * user.Surname = input.Surname; * user.EmailAddress = input.EmailAddress; * userInput.IsActive = input.IsActive; * userInput.TenantId = AbpSession.TenantId; * userInput.IsEmailConfirmed = true; */ userInput.TenantId = AbpSession.TenantId; userInput.Password = new PasswordHasher().HashPassword(input.Password); //CheckErrors(await UserManager.UpdateAsync(userInput)); } _userRepository.InsertOrUpdate(userInput); }); } catch (Exception ex) { throw ex; } }
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); //}); }
public UserInputViewModel(UserInputDto output) { output.MapTo(this); }