public async Task AddUserAsync(AddUserModel model) { if (string.IsNullOrEmpty(model.Account)) { throw new InvalidOperationException("账号不能为空"); } if (model.Account.Length > 50) { throw new InvalidOperationException("账号长度不能大于50"); } if (string.IsNullOrEmpty(model.Name)) { throw new InvalidOperationException("名称不能为空"); } if (model.Name.Length > 50) { throw new InvalidOperationException("名称长度不能大于50"); } User userFromDB; if (!string.IsNullOrEmpty(model.Account)) { userFromDB = await _userRepository.FirstOrDefaultAsync(m => m.Account == model.Account); if (userFromDB != null) { throw new InvalidOperationException("账户已存在"); } } userFromDB = model.CopyProperties <User>(); userFromDB.Password = GetEncodePassword(DefaultPassword); _unitOfWork.RegisterAdd(userFromDB); await _unitOfWork.CommitAsync(); }
public async Task AddUserAsync(AddUserModel model) { if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account))) { throw new MateralConfigCenterException("账号已存在"); } var user = model.CopyProperties <User>(); user.Password = PasswordHelper.GetEncodePassword(string.IsNullOrEmpty(model.Password) ? "123456" : user.Password); _authorityUnitOfWork.RegisterAdd(user); await _authorityUnitOfWork.CommitAsync(); }
public async Task AddUserAsync(AddUserModel model) { if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account))) { throw new MateralConfigCenterException("账号已存在"); } var user = model.CopyProperties <User>(); user.Password = string.IsNullOrEmpty(model.Password) ? "123456".ToMd5() : user.Password.ToMd5(); _protalServerUnitOfWork.RegisterAdd(user); await _protalServerUnitOfWork.CommitAsync(); }
public async Task AddUserAsync(AddUserModel model) { if (string.IsNullOrEmpty(model.Name)) { throw new InvalidOperationException("名称为空"); } if (!string.IsNullOrEmpty(model.Account) && await _userRepository.CountAsync(m => m.Account == model.Account) > 0) { throw new InvalidOperationException("账户重复"); } var user = model.CopyProperties <User>(); user.Password = GetEncodePassword(DefaultPassword); AddUserRoles(user, model.RoleIDs); _authorityUnitOfWork.RegisterAdd(user); await _authorityUnitOfWork.CommitAsync(); }