public virtual async Task <IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) { await IdentityOptions.SetAsync(); var user = await UserManager.GetByIdAsync(id); user.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); await UpdateUserByInput(user, input); input.MapExtraPropertiesTo(user); (await UserManager.UpdateAsync(user)).CheckErrors(); if (!input.Password.IsNullOrEmpty()) { (await UserManager.RemovePasswordAsync(user)).CheckErrors(); (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors(); } await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <IdentityUser, IdentityUserDto>(user)); }
public async Task UpdateAsync_Concurrency_Exception() { //Get user var johnNash = await _userAppService.GetAsync(_testData.UserJohnId); //Act var input = new IdentityUserUpdateDto { Name = "John-updated", Surname = "Nash-updated", UserName = johnNash.UserName, LockoutEnabled = true, PhoneNumber = CreateRandomPhoneNumber(), Email = CreateRandomEmail(), RoleNames = new[] { "admin", "moderator" }, ConcurrencyStamp = johnNash.ConcurrencyStamp }; await _userAppService.UpdateAsync(johnNash.Id, input); //Second update with same input will throw exception because the entity has been modified (await Assert.ThrowsAsync <AbpIdentityResultException>(async() => { await _userAppService.UpdateAsync(johnNash.Id, input); })).Message.ShouldContain("Optimistic concurrency failure"); }
public async Task <IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) { var user = await UserManager.GetByIdAsync(id); user.ConcurrencyStamp = input.ConcurrencyStamp; (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); await UpdateUserByInput(user, input); input.MapExtraPropertiesTo(user); (await UserManager.UpdateAsync(user)).CheckErrors(); if (!input.Password.IsNullOrEmpty()) { (await UserManager.RemovePasswordAsync(user)).CheckErrors(); (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors(); } var dto = ObjectMapper.Map <IdentityUser, IdentityUserDto>(user); await _userJobsRepository.DeleteAsync(_ => _.UserId == id); foreach (var jid in input.Jobs) { await _userJobsRepository.InsertAsync(new UserJobs(id, jid)); } await CurrentUnitOfWork.SaveChangesAsync(); return(dto); }
public virtual async Task <IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) { return(await RequestAsync <IdentityUserDto>(nameof(UpdateAsync), new ClientProxyRequestTypeValue { { typeof(Guid), id }, { typeof(IdentityUserUpdateDto), input } })); }
public virtual async Task <IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) { try { await IdentityOptions.SetAsync(); } catch (Exception e) { throw; } var user = await UserManager.GetByIdAsync(id); user.ConcurrencyStamp = input.ConcurrencyStamp; (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); await UpdateUserByInput(user, input); input.MapExtraPropertiesTo(user); // TODO: this is another issue. // It throws an error without casting the type int to enum type before saving the user var userType = user.GetProperty <int>("Type"); UserType type = (UserType)userType; user.SetProperty("Type", type); (await UserManager.UpdateAsync(user)).CheckErrors(); if (!input.Password.IsNullOrEmpty()) { (await UserManager.RemovePasswordAsync(user)).CheckErrors(); (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors(); } await CurrentUnitOfWork.SaveChangesAsync(); return(ObjectMapper.Map <IdentityUser, IdentityUserDto>(user)); }
public async Task UpdateAsync() { //Arrange var johnNash = GetUser("john.nash"); var input = new IdentityUserUpdateDto { UserName = johnNash.UserName, LockoutEnabled = true, PhoneNumber = CreateRandomPhoneNumber(), Password = "******", Email = CreateRandomEmail(), RoleNames = new[] { "admin", "moderator" }, ConcurrencyStamp = johnNash.ConcurrencyStamp, Surname = johnNash.Surname, Name = johnNash.Name }; //Act var result = await _userAppService.UpdateAsync(johnNash.Id, input); //Assert result.Id.ShouldBe(johnNash.Id); result.UserName.ShouldBe(input.UserName); result.Email.ShouldBe(input.Email); result.LockoutEnabled.ShouldBe(input.LockoutEnabled); result.PhoneNumber.ShouldBe(input.PhoneNumber); var user = await _userRepository.GetAsync(result.Id); user.Id.ShouldBe(result.Id); user.UserName.ShouldBe(input.UserName); user.Email.ShouldBe(input.Email); user.LockoutEnabled.ShouldBe(input.LockoutEnabled); user.PhoneNumber.ShouldBe(input.PhoneNumber); user.Roles.Count.ShouldBe(2); }
public Task <IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) { return(_userAppService.UpdateAsync(id, input)); }
public virtual Task <IdentityUserDto> UpdateAsync(string id, IdentityUserUpdateDto input) { return(_userAppService.UpdateAsync(id.ToGuid(), input)); }
/// <summary> /// 更新用户 /// </summary> /// <param name="id">Id标识</param> /// <param name="parameters">请求参数</param> /// <returns>Task<IdentityUserDto>.</returns> public virtual Task <IdentityUserDto> Update(string id, IdentityUserUpdateDto parameters) { return(_userAppService.UpdateAsync(id.ToGuid(), parameters)); }