public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } using (var tran = _permissionRepository.BeginTransaction()) { foreach (var permission in permissions) { if (!await _permissionRepository.Exists(permission, tran)) { if (!await _permissionRepository.AddAsync(permission, tran)) { tran.Rollback(); return(ResultModel.Failed("同步失败")); } } else { if (!await _permissionRepository.UpdateForSync(permission, tran)) { tran.Rollback(); return(ResultModel.Failed("同步失败")); } } } tran.Commit(); } return(ResultModel.Success()); }