Esempio n. 1
0
        public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto input)
        {
            input.NotNull(nameof(input));
            var user = await _userManager.FindByIdAsync(input.Id.ToString());

            user = input.MapTo(user);
            return((await _userManager.UpdateAsync(user)).ToOperationResponse());
            //return result;
            //return await _unitOfWork.UseTranAsync(async () =>
            //{

            //    if (!result.Succeeded)
            //        return result.ToOperationResponse();
            //    await _userRoleRepository.DeleteBatchAsync(x => x.UserId == input.Id);
            //    if (input.RoleIds?.Any() == true)
            //    {
            //        await _userRoleRepository.InsertAsync(input.RoleIds.Select(x => new UserRoleEntity
            //        {
            //            RoleId = x,
            //            UserId = user.Id,
            //        }).ToArray());
            //    }
            //    return new OperationResponse(ResultMessage.UpdateSuccess, OperationEnumType.Success);
            //});
        }
Esempio n. 2
0
 public async Task <IActionResult> UpdateUserMobile([FromBody] UserUpdateInputDto input)
 {
     if (!string.IsNullOrEmpty(input.Id) && !string.IsNullOrEmpty(input.Mobile))
     {
         var(user, appService) = _userAppServiceClient.FindByUserIdAsync(input.Id).Result;
         if (user != null)
         {
             if (user.Mobile == input.Mobile)
             {
                 return(Json(false, null, "新手机号码不能和原手机号码相同"));
             }
             if (await _userAppServiceClient.IsMobileExistedAsync(input.Mobile))
             {
                 return(Json(false, null, "手机号码已经存在"));
             }
             if (await appService.UpdateUserAsync(user.Id, new UserItemDto {
                 Mobile = input.Mobile
             }) != null)
             {
                 user.Mobile = input.Mobile;
                 return(Json(true, user, "操作成功"));
             }
         }
     }
     return(Json(false, null, "未找到相关的用户信息"));
 }
Esempio n. 3
0
        public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto 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);
                }
                else
                {
                    return await this.DeleteUserRoleAsync(user);
                }
            }));
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdateUserPassword([FromBody] UserUpdateInputDto input)
        {
            if (!string.IsNullOrEmpty(input.Id) && !string.IsNullOrEmpty(input.RePassword) &&
                !string.IsNullOrEmpty(input.Password) && input.Password == input.RePassword)
            {
                var(user, appService) = _userAppServiceClient.FindByUserIdAsync(input.Id).Result;
                if (user != null)
                {
                    if (await appService.UpdateUserAsync(user.Id, new UserItemDto {
                        Password = input.Password
                    }) != null)
                    {
                        return(new JsonResult(new AjaxResult()
                        {
                            Success = true, Message = "操作成功"
                        }));
                    }


                    return(new JsonResult(new AjaxResult()
                    {
                        Success = false, Message = "操作失败"
                    }));
                }
            }
            return(new JsonResult(new AjaxResult()
            {
                Success = false, Message = "操作失败:未找到用户|密码不一致|密码不能为空"
            }));
        }
Esempio n. 5
0
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <StatusResult> UpdateAsync(UserUpdateInputDto input)
        {
            var user = await _userRepository.Select.Where(o => o.Id == input.Id).FirstAsync();

            if (user == null)
            {
                return(new StatusResult("用户不存在!"));
            }
            var thisUser = new UserEntity()
            {
                Id = input.Id
            };

            _userRepository.Attach(thisUser);
            thisUser.Avatar   = input.Avatar;
            thisUser.NickName = input.NickName;
            thisUser.Phone    = input.Phone;
            thisUser.RealName = input.RealName;
            int res = await _userRepository.UpdateAsync(thisUser);

            await _userRoleRepository.DeleteAsync(o => o.UserId == user.Id);

            var userRoles = input.RoleIds.Select(o => new UserRoleEntity()
            {
                RoleId = o.key,
                UserId = user.Id,
                Id     = Snowflake.GenId()
            });
            await _userRoleRepository.InsertAsync(userRoles);

            return(new StatusResult(res == 0, "修改失败"));
        }
Esempio n. 6
0
        public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto dto)
        {
            dto.NotNull(nameof(dto));
            var user = await _userManager.FindByIdAsync(dto.Id.ToString());

            user = dto.MapTo(user);
            var result = await _userManager.UpdateAsync(user);

            return(result.ToOperationResponse("保存用户成功"));
        }
Esempio n. 7
0
        public async Task Update(UserUpdateInputDto inputDto)
        {
            var user = await _userManager.GetById(inputDto.Id);

            if (user == null)
            {
                throw new APIException("用户信息不存在。");
            }

            inputDto.MapTo(user);
            await _userManager.Update(user);
        }
Esempio n. 8
0
        public async Task UpdateUser(UserUpdateInputDto request)
        {
            var userVerified = _repository.GetUserWithDetail(request.Id);

            if (userVerified != null)
            {
                //userVerified.UserProfile.BirthDate = request.BirthDate;
                //userVerified.UserProfile.FirstName = request.FirstName;
                //userVerified.UserProfile.LastName = request.LastName;
                //userVerified.UserProfile.MobilePhone = request.MobilePhone;
                await _userManager.UpdateAsync(userVerified);
            }
            else
            {
                throw new Exception("User is not existing in our records.");
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> UpdateUserState([FromBody] UserUpdateInputDto input)
        {
            if (!string.IsNullOrEmpty(input.Id))
            {
                var(user, appService) = await _userAppServiceClient.FindByUserIdAsync(input.Id);

                if (user != null)
                {
                    if (await appService.UpdateUserAsync(user.Id, new UserItemDto {
                        IsActive = !user.IsActive
                    }) != null)
                    {
                        return(Json(true, null, "修改成功"));
                    }
                }
            }
            return(Json(false, null, "未找到当前用户"));
        }
Esempio n. 10
0
 public async Task <AjaxResult> UpdateAsync([FromBody] UserUpdateInputDto input)
 {
     return((await _userContract.UpdateAsync(input)).ToAjaxResult());
 }
Esempio n. 11
0
 public async Task <AjaxResult> UpdateAsync([FromBody] UserUpdateInputDto dto)
 {
     return((await _userService.UpdateAsync(dto)).ToAjaxResult());
 }
Esempio n. 12
0
        public async Task <HttpResponse <int> > Update(UserUpdateInputDto inputDto)
        {
            await _userAppService.Update(inputDto);

            return(Success(0));
        }
Esempio n. 13
0
 public async Task <StatusResult> Update(UserUpdateInputDto input)
 {
     return(await _userService.UpdateAsync(input));
 }