/// <summary> /// 添加角色信息 /// </summary> /// <param name="roleId"></param> /// <param name="accountId"></param> /// <returns></returns> public async Task AddAsync(IEnumerable <string> roleId, int accountId) { IList <SysRoleAdminUserInfo> sysRoleAdminUserInfos = new List <SysRoleAdminUserInfo>(); IEnumerable <SysRole> sysRoles = await _sysRoleService.GetFullListAsync(_ => roleId.Contains(_.Id)); foreach (var item in roleId) { SysRoleAdminUserInfo sysRoleAdminUserInfo = new SysRoleAdminUserInfo(accountId, item, sysRoles.FirstOrDefault(_ => _.Id == item)?.RoleCode); sysRoleAdminUserInfos.Add(sysRoleAdminUserInfo); } IEnumerable <SysRoleAdminUserInfo> sysRoleAdmins = await GetFullListAsync(_ => _.AccountId == accountId); await ServiceBase.ResilientTransaction.New(BaseData.BaseDB.BaseDataContext).ExecuteAsync(async() => { if (sysRoleAdmins.Any()) { await DeleteAllAsync(sysRoleAdmins); } if (sysRoleAdminUserInfos.Any()) { await SaveObjectListAsync(sysRoleAdminUserInfos); } }); }
/// <summary> /// 添加角色信息 /// </summary> /// <param name="roleId"></param> /// <param name="accountId"></param> /// <returns></returns> public async Task AddAsync(IEnumerable <string> roleId, int accountId) { IList <SysRoleAdminUserInfo> sysRoleAdminUserInfos = new List <SysRoleAdminUserInfo>(); IEnumerable <SysRole> sysRoles = await _sysRoleService.GetFullListAsync(_ => roleId.Contains(_.Id)); foreach (var item in roleId) { SysRoleAdminUserInfo sysRoleAdminUserInfo = new SysRoleAdminUserInfo(accountId, item, sysRoles.FirstOrDefault(_ => _.Id == item)?.RoleCode); sysRoleAdminUserInfos.Add(sysRoleAdminUserInfo); } IEnumerable <SysRoleAdminUserInfo> sysRoleAdmins = await GetFullListAsync(_ => _.AccountId == accountId); await BeginTransactionAsync(async() => { if (sysRoleAdmins.Any()) { await DeleteAllAsync(sysRoleAdmins); } if (sysRoleAdminUserInfos.Any()) { await SaveObjectListAsync(sysRoleAdminUserInfos); } }, ex => { return(new NotSupportedException("不支持")); }); }