public async Task <IResultModel <Guid> > Add(AccountAddModel model) { var result = new ResultModel <Guid>(); var account = _mapper.Map <AccountEntity>(model); var exists = await Exists(account); if (!exists.Successful) { return(exists); } //设置默认密码 if (account.LoginPwd.IsNull()) { account.LoginPwd = "123456"; } account.PassSalt = new StringHelper().GenerateRandom(8); account.LoginPwd = Zoomtel.Utils.Helpers.Encrypt.DESEncrypt(account.LoginPwd, account.PassSalt); _accountRepository.BeginTrans(); if (await _accountRepository.InsertAsync(account) > 0) { //插入角色绑定信息 if (model.RoleList != null && model.RoleList.Count > 0) { var accountRoleList = model.RoleList.Select(m => new AccountRoleEntity { Uid = account.Uid, RoleId = m }).ToList(); if (await _accountRoleRepository.InsertAsync(accountRoleList) > 0) { _accountRepository.Commit(); return(result.Success(account.Uid)); } } else { _accountRepository.Commit(); return(result.Success(account.Uid)); } } return(result.Failed()); }