Пример #1
0
        public async Task <string> Update(UpdateUserInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();

            var userInfo = await _userRepository.SingleOrDefaultAsync(p => p.Id == input.Id);

            if (userInfo == null)
            {
                throw new BusinessException($"不存在Id为{input.Id}的用户信息");
            }
            if (input.Email != userInfo.Email)
            {
                var exsitUser = await _userRepository.FirstOrDefaultAsync(p => p.Email == input.Email);

                if (exsitUser != null)
                {
                    throw new BusinessException($"系统中已经存在{input.Email}的用户信息");
                }
            }
            if (input.Phone != userInfo.Phone)
            {
                var exsitUser = await _userRepository.FirstOrDefaultAsync(p => p.Phone == input.Phone);

                if (exsitUser != null)
                {
                    throw new BusinessException($"系统中已经存在{input.Phone}的用户信息");
                }
            }
            userInfo = input.MapTo(userInfo);
            await _userRepository.UpdateAsync(userInfo);

            return("更新员工信息成功");
        }
Пример #2
0
        public bool editInfo(UpdateUserInput input, int[] roleIds)
        {
            var user = db.Users.Find(input.ID);

            if (user == null)
            {
                throw new UserFriendlyException(LocalizationConst.UserNoExist);
            }

            user            = input.MapTo(user);
            user.ModifyTime = DateTime.Now;
            user.ModifyIP   = IPHelper.GetIPAddress;

            var list = db.UserRoles.Where(a => a.UserID == user.ID);

            db.UserRoles.RemoveRange(list);

            var Roles     = db.Roles.Where(a => roleIds.Contains(a.ID));
            var userRoles = new List <UserRole>();

            foreach (var role in Roles)
            {
                userRoles.Add(new UserRole()
                {
                    User = user, Role = role
                });
            }
            db.UserRoles.AddRange(userRoles);

            db.Entry(user).State = EntityState.Modified;
            return(db.SaveChanges() > 0);
        }
Пример #3
0
        /// <inheritdoc/>
        public async Task UpdateUser(UpdateUserInput input)
        {
            var user = await UserManager.GetUserByIdAsync(input.Id);

            input.MapTo(user);
            await UserManager.UpdateAsync(user);
        }
Пример #4
0
        public async Task Update(UpdateUserInput input)
        {
            var updateUser = await _userRepository.SingleOrDefaultAsync(p => p.Id == input.Id, false);

            if (updateUser == null)
            {
                throw new BusinessException($"不存在Id为{input.Id}的账号信息");
            }
            if (input.Phone != updateUser.Phone)
            {
                var existUser = await _userRepository.FirstOrDefaultAsync(p => p.Phone == input.Phone, false);

                if (existUser != null)
                {
                    throw new UserFriendlyException($"已经存在手机号码为{input.Phone}的用户");
                }
            }

            if (input.Email != updateUser.Email)
            {
                var existUser = await _userRepository.FirstOrDefaultAsync(p => p.Email == input.Email, false);

                if (existUser != null)
                {
                    throw new UserFriendlyException($"已经存在Email为{input.Email}的用户");
                }
            }

            var departAppServiceProxy = GetService <IDepartmentAppService>();

            if (input.OrgId.HasValue)
            {
                if (!await departAppServiceProxy.Check(input.OrgId.Value))
                {
                    throw new BusinessException($"不存在Id为{input.OrgId}的部门信息");
                }
            }

            var positionAppServiceProxy = GetService <IPositionAppService>();

            if (input.PositionId.HasValue)
            {
                if (!await positionAppServiceProxy.CheckExsit(input.PositionId.Value))
                {
                    throw new BusinessException($"不存在Id为{input.PositionId}的职位信息");
                }
            }

            updateUser = input.MapTo(updateUser);
            using (var locker = await _lockerProvider.CreateLockAsync("UpdateUser"))
            {
                await locker.Lock(async() =>
                {
                    await UnitOfWorkAsync(async(conn, trans) =>
                    {
                        await _userRepository.UpdateAsync(updateUser, conn, trans);
                        await _userRoleRepository.DeleteAsync(p => p.UserId == updateUser.Id, conn, trans);
                        await _userUserGroupRelationRepository.DeleteAsync(p => p.UserId == updateUser.Id, conn, trans);
                        foreach (var roleId in input.RoleIds)
                        {
                            var role = await _roleRepository.SingleOrDefaultAsync(p => p.Id == roleId);
                            if (role == null)
                            {
                                throw new BusinessException($"系统中不存在Id为{roleId}的角色信息");
                            }

                            await _userRoleRepository.InsertAsync(
                                new UserRole {
                                UserId = updateUser.Id, RoleId = roleId
                            }, conn, trans);
                        }

                        foreach (var userGroupId in input.UserGroupIds)
                        {
                            var userGroup = await _userGroupRepository.SingleOrDefaultAsync(p => p.Id == userGroupId);
                            if (userGroup == null)
                            {
                                throw new BusinessException($"系统中不存在Id为{userGroupId}的用户组信息");
                            }

                            await _userUserGroupRelationRepository.InsertAsync(
                                new UserUserGroupRelation {
                                UserId = updateUser.Id, UserGroupId = userGroupId
                            }, conn,
                                trans);
                        }
                    }, Connection);
                });
            }
        }
Пример #5
0
        public async Task UpdateUser(UpdateUserInput input)
        {
            var user = await _userRepository.GetAsync(input.Id);

            input.MapTo(user);
        }