public async Task EditUserAsync(EditUserModel model)
        {
            if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account) && m.ID != model.ID))
            {
                throw new MateralConfigCenterException("账号已存在");
            }
            User userFromDb = await _userRepository.FirstOrDefaultAsync(model.ID);

            if (userFromDb == null)
            {
                throw new MateralConfigCenterException("用户不存在");
            }
            string oldPassword = userFromDb.Password;

            model.CopyProperties(userFromDb);
            userFromDb.Password   = string.IsNullOrEmpty(model.Password) ? oldPassword : PasswordHelper.GetEncodePassword(model.Password);
            userFromDb.UpdateTime = DateTime.Now;
            _authorityUnitOfWork.RegisterEdit(userFromDb);
            await _authorityUnitOfWork.CommitAsync();
        }
Esempio n. 2
0
        public async Task EditUserAsync(EditUserModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _userRepository.CountAsync(m => m.ID != model.ID && m.Account == model.Account) > 0)
            {
                throw new InvalidOperationException("账户重复");
            }
            User userFromDB = await _userRepository.FirstOrDefaultAsync(model.ID);

            if (userFromDB == null)
            {
                throw new InvalidOperationException("用户不存在");
            }
            model.CopyProperties(userFromDB);
            await EditUserRoles(userFromDB, model.RoleIDs);

            _authorityUnitOfWork.RegisterEdit(userFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Esempio n. 3
0
        public async Task EditUserAsync(EditUserModel model)
        {
            User userFromDB;

            if (!string.IsNullOrEmpty(model.Account))
            {
                userFromDB = await _userRepository.FirstOrDefaultAsync(m => m.Account == model.Account && m.ID != model.ID);

                if (userFromDB != null)
                {
                    throw new InvalidOperationException("账户已存在");
                }
            }
            userFromDB = await _userRepository.FirstOrDefaultAsync(model.ID);

            if (userFromDB == null)
            {
                throw new InvalidOperationException("用户不存在");
            }
            model.CopyProperties(userFromDB);
            userFromDB.UpdateTime = DateTime.Now;
            _unitOfWork.RegisterEdit(userFromDB);
            await _unitOfWork.CommitAsync();
        }