예제 #1
0
        public void ChangeState(string id, AccountState newState)
        {
            id.NotNullOrEmpty();
            SysUser user = this.Query.Where(a => a.Id == id).AsTracking().FirstOrDefault();

            user.EnsureIsNotAdmin();
            if (user == null)
            {
                throw new InvalidInputException("用户不存在");
            }
            if (user.State == AccountState.Closed)
            {
                throw new InvalidInputException("用户已注销,无法操作");
            }

            List <AccountState> list = new List <AccountState>()
            {
                AccountState.Normal, AccountState.Disabled, AccountState.Closed
            };

            if (newState.In(list) == false)
            {
                throw new InvalidInputException("状态无效:" + newState.ToString());
            }

            user.State = newState;

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Update(user);
                //this.Log(LogType.Update, "User", true, $"用户[{this.Session.UserId}]修改用户[{id}]状态为:{newState}");
            });
        }