コード例 #1
0
        public ActionResult Update(UpdateUserInput input)
        {
            input.Validate();
            var services = this.CreateService <IAccountAppService>();

            var user = services.GetById <Sys_User>(input.Id);

            user.RoleId           = input.RoleId;
            user.RealName         = input.RealName;
            user.IsEnabled        = input.IsEnabled;
            user.Description      = input.Description;
            user.LastModifyUserId = CurrentSession.UserId;
            user.LastModifyTime   = DateTime.Now;
            services.Update(user);
            return(this.UpdateSuccessMsg());
        }
コード例 #2
0
        public void UpdateUser(UpdateUserInput input)
        {
            input.Validate();

            this.DbContext.Update <MALU_Users>(a => a.Id == input.Id, a => new MALU_Users()
            {
                //OrganizeId = input.OrganizeId,
                RoleId      = input.RoleId,
                DutyId      = input.DutyId,
                RealName    = input.RealName,
                Gender      = input.Gender,
                MobilePhone = input.MobilePhone,
                Birthday    = input.Birthday,
                IsEnabled   = input.IsEnabled,
                companyguid = input.companyguid
            });
        }
コード例 #3
0
ファイル: UserAppService.cs プロジェクト: zwq194/Ace
        public void UpdateUser(UpdateUserInput input)
        {
            input.Validate();

            this.DbContext.Update <Sys_User>(a => a.Id == input.Id, a => new Sys_User()
            {
                //OrganizeId = input.OrganizeId,
                DepartmentId = input.DepartmentId,
                RoleId       = input.RoleId,
                DutyId       = input.DutyId,
                RealName     = input.RealName,
                Gender       = input.Gender,
                MobilePhone  = input.MobilePhone,
                Birthday     = input.Birthday,
                WeChat       = input.WeChat,
                Email        = input.Email,
                IsEnabled    = input.IsEnabled,
                Description  = input.Description,
            });
        }
コード例 #4
0
ファイル: IUserService.cs プロジェクト: xman01111/MrcCore
        public void Update(UpdateUserInput input)
        {
            this.Trim(input);

            input.Validate();

            Sys_User user = this.Query.Where(a => a.Id == input.Id).AsTracking().First();

            user.EnsureIsNotAdmin();
            if (user.State == AccountState.Closed)
            {
                throw new InvalidInputException("无法修改已注销用户");
            }

            string accountName = null;

            if (user.AccountName.IsNullOrEmpty())
            {
                //用户名设置后不能修改
                if (input.AccountName.IsNotNullOrEmpty())
                {
                    accountName = input.AccountName.ToLower();

                    bool exists = this.DbContext.Query <Sys_User>().Where(a => a.AccountName == accountName).Any();
                    if (exists)
                    {
                        throw new InvalidInputException("用户名[{0}]已存在".ToFormat(input.AccountName));
                    }
                }
            }
            else
            {
                accountName = user.AccountName;
            }

            string mobilePhone = null;

            if (user.MobilePhone.IsNotNullOrEmpty() && input.MobilePhone.IsNullOrEmpty())
            {
                //手机号码设置后不能再改为空
                throw new InvalidInputException("请输入手机号码");
            }
            if (input.MobilePhone.IsNotNullOrEmpty())
            {
                mobilePhone = input.MobilePhone;
                //if (AceUtils.IsMobilePhone(mobilePhone) == false)
                //    throw new InvalidInputException("请输入正确的手机号码");

                if (user.MobilePhone != mobilePhone)//不等说明手机号码有变
                {
                    bool exists = this.DbContext.Query <Sys_User>().Where(a => a.MobilePhone == mobilePhone).Any();
                    if (exists)
                    {
                        throw new InvalidInputException("手机号码[{0}]已存在".ToFormat(mobilePhone));
                    }
                }
            }

            string email = null;

            if (user.Email.IsNotNullOrEmpty() && input.Email.IsNullOrEmpty())
            {
                //邮箱地址设置后不能再改为空
                throw new InvalidInputException("请输入邮箱地址");
            }
            if (input.Email.IsNotNullOrEmpty())
            {
                email = input.Email.ToLower();
                //if (AceUtils.IsEmail(email) == false)
                //    throw new InvalidInputException("请输入正确的邮箱地址");

                if (user.Email != email)//不等说明邮箱有变
                {
                    bool exists = this.DbContext.Query <Sys_User>().Where(a => a.Email == email).Any();
                    if (exists)
                    {
                        throw new InvalidInputException("邮箱地址[{0}]已存在".ToFormat(input.Email));
                    }
                }
            }

            user.AccountName = accountName;
            user.Name        = input.Name;
            user.Gender      = input.Gender;
            user.MobilePhone = mobilePhone;
            user.Birthday    = input.Birthday;
            user.WeChat      = input.WeChat;
            user.Email       = email;
            user.Description = input.Description;

            List <string>       roleIds           = input.GetRoles();
            List <Sys_UserRole> userRoles         = this.DbContext.Query <Sys_UserRole>().Where(a => a.UserId == input.Id).ToList();
            List <string>       userRolesToDelete = userRoles.Where(a => !roleIds.Contains(a.Id)).Select(a => a.Id).ToList();
            List <Sys_UserRole> userRolesToAdd    = roleIds.Where(a => !userRoles.Any(r => r.Id == a)).Select(a =>
            {
                return(new Sys_UserRole()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = input.Id,
                    RoleId = a,
                });
            }).ToList();

            user.RoleIds = string.Join(",", roleIds);

            List <string>      orgIds           = input.GetOrgs();
            List <Sys_UserOrg> userOrgs         = this.DbContext.Query <Sys_UserOrg>().Where(a => a.UserId == input.Id).ToList();
            List <string>      userOrgsToDelete = userOrgs.Where(a => !orgIds.Contains(a.Id)).Select(a => a.Id).ToList();
            List <Sys_UserOrg> userOrgsToAdd    = orgIds.Where(a => !userOrgs.Any(r => r.Id == a)).Select(a =>
            {
                return(new Sys_UserOrg()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = input.Id,
                    OrgId = a,
                    DisablePermission = false
                });
            }).ToList();

            user.OrgIds = string.Join(",", orgIds);

            List <string>       postIds   = input.GetPosts();
            List <Sys_UserPost> userPosts = postIds.Select(a =>
            {
                return(new Sys_UserPost()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = input.Id,
                    PostId = a
                });
            }).ToList();

            user.PostIds = string.Join(",", postIds);

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Delete <Sys_UserRole>(a => a.Id.In(userRolesToDelete));
                this.DbContext.InsertRange(userRolesToAdd);

                this.DbContext.Delete <Sys_UserOrg>(a => a.Id.In(userOrgsToDelete));
                this.DbContext.InsertRange(userOrgsToAdd);

                this.DbContext.Delete <Sys_UserPost>(a => a.UserId == input.Id);
                this.DbContext.InsertRange(userPosts);

                this.DbContext.Update <Sys_User>(user);
            });
        }