public async Task Delete(long roleid) { var role = await _roleRepository.SingleOrDefaultAsync(p => p.Id == roleid); if (role == null) { throw new BusinessException($"不存在Id为{roleid}的角色信息"); } var userRoleCount = await _userRoleRepository.GetCountAsync(p => p.RoleId == roleid); if (userRoleCount > 0) { throw new BusinessException($"{role.Name}被分配用户,请先删除相关授权的用户信息"); } var userGroupRoleCount = await _userGroupRoleRepository.GetCountAsync(p => p.RoleId == roleid); if (userRoleCount > 0) { throw new BusinessException($"{role.Name}被分配用户组,请先删除相关授权的用户组信息"); } await UnitOfWorkAsync(async(conn, trans) => { await _roleRepository.DeleteAsync(p => p.Id == roleid, conn, trans); await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans); }, Connection); }
public async Task DeleteDepartmentByOrgId(long orgId) { var department = await _departmentRepository.SingleOrDefaultAsync(p => p.OrgId == orgId); var orgInfo = await _organizationRepository.SingleOrDefaultAsync(p => p.Id == orgId); if (department == null || orgInfo == null) { throw new BusinessException($"系统中不存在Id为{orgId}的部门信息"); } var children = await _organizationRepository.GetAllAsync(p => p.ParentId == orgId); if (children.Any()) { throw new BusinessException($"请先删除子部门信息"); } var departmentUsers = await GetService <IUserAppService>().GetOrgUser(orgInfo.Id, true); //if (departmentUsers.Any()) { // throw new BusinessException($"该部门存在用户,请先删除该部门下的用户"); //} await UnitOfWorkAsync(async (conn, trans) => { await _organizationRepository.DeleteAsync(orgInfo, conn, trans); await _departmentRepository.DeleteAsync(department, conn, trans); await _positionRepository.DeleteAsync(p => p.DeptId == department.Id, conn, trans); foreach (var departmentUser in departmentUsers) { if (!await GetService <IUserAppService>().ResetUserOrgInfo(departmentUser.Id)) { throw new BusinessException("重置该公司部门员工部门信息失败,请稍后重试"); } } }, Connection); }
public async Task Create(CreateRoleInput input) { var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Name == input.Name); if (exsitRole != null) { throw new BusinessException($"系统中已经存在{input.Name}的角色"); } var role = input.MapTo <Role>(); await UnitOfWorkAsync(async (conn, trans) => { var roleId = await _roleRepository.InsertAndGetIdAsync(role, conn, trans); var queryOperationSql = "SELECT o.* FROM `Operation` as o LEFT JOIN Permission as p ON o.PermissionId = p.Id AND p.IsDeleted = 0 AND o.IsDeleted = 0 WHERE o.PermissionId IN @PermissionIds"; var operations = await conn.QueryAsync <Operation>(queryOperationSql, new { PermissionIds = input.PermissionIds }, transaction: trans); if (!operations.Any(p => p.Mold == Shared.Operations.OperationMold.Query || p.Mold == Shared.Operations.OperationMold.Look)) { throw new BusinessException($"分配的权限至少要包含查询或是查看类型操作"); } await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleId, conn, trans); foreach (var permissionId in input.PermissionIds) { var permission = await _permissionRepository.SingleOrDefaultAsync(p => p.Id == permissionId); if (permission == null) { throw new BusinessException($"不存在Id为{permissionId}的权限信息"); } await _rolePermissionRepository.InsertAsync(new RolePermission() { PermissionId = permissionId, RoleId = roleId }, conn, trans); } }, Connection); }
public async Task Delete(long permissionId) { var menu = await _menuRepository.SingleOrDefaultAsync(p => p.PermissionId == permissionId); if (menu == null) { throw new BusinessException($"不存在PermissionId为{permissionId}的菜单信息"); } var allNeedDeleteMenus = await _menuRepository.GetAllAsync(p => p.Code.Contains(menu.Code)); await UnitOfWorkAsync(async (conn, trans) => { await _menuRepository.DeleteAsync(p => p.Code.Contains(menu.Code), conn, trans); foreach (var needDeleteMenu in allNeedDeleteMenus) { await _permissionRepository.DeleteAsync(p => p.Id == needDeleteMenu.PermissionId, conn, trans); var operations = await _operationRepository.GetAllAsync(p => p.MenuId == needDeleteMenu.Id); await _operationRepository.DeleteAsync(p => p.MenuId == needDeleteMenu.Id, conn, trans); if (operations.Any()) { foreach (var operation in operations) { await _operationActionRepository.DeleteAsync(p => p.OperationId == operation.Id, conn, trans); await _permissionRepository.DeleteAsync(p => p.Id == operation.PermissionId, conn, trans); } } } }, Connection); }
public async Task Delete(long id) { var userGroup = await _userGroupRepository.SingleOrDefaultAsync(p => p.Id == id); if (userGroup == null) { throw new BusinessException($"不存在Id为{id}的用户组信息"); } // _session.CheckLoginUserDataPermision(userGroup.DataPermissionType,"您设置的用户组的数据权限大于您拥有数据权限,系统不允许该操作"); using (var locker = await _lockerProvider.CreateLockAsync("DeleteUserGroup")) { await locker.Lock(async() => { await UnitOfWorkAsync(async(conn, trans) => { await _userGroupRepository.DeleteAsync(p => p.Id == id, conn, trans); await _userGroupRoleRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); await _userUserGroupRelationRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); await _userGroupDataPermissionOrgRelationRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); await _userGroupOrganizationRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); await RemoveUserGroupCheckPemissionCache(id); }, Connection); }); } }
public async Task Delete(long id) { await UnitOfWorkAsync(async (conn, trans) => { await _userRepository.DeleteAsync(p => p.Id == id, conn, trans); await _userRoleRepository.DeleteAsync(p => p.UserId == id, conn, trans); await _userUserGroupRelationRoleRepository.DeleteAsync(p => p.UserId == id, conn, trans); // todo: 删除其他关联表 }, Connection); }
public async Task Delete(long permissionId) { var operation = await _operationRepository.SingleOrDefaultAsync(p => p.PermissionId == permissionId); if (operation == null) { throw new BusinessException($"不存在permissionId为{permissionId}的操作信息"); } await UnitOfWorkAsync(async (conn, trans) => { await _operationRepository.DeleteAsync(p => p.PermissionId == permissionId, conn, trans); await _operationActionRepository.DeleteAsync(p => p.OperationId == operation.Id, conn, trans); await _permissionRepository.DeleteAsync(p => p.Id == operation.PermissionId, conn, trans); }, Connection); }
public async Task DeleteCorporation(long orgId) { var corporation = await _corporationRepository.SingleOrDefaultAsync(p => p.OrgId == orgId); var orgInfo = await _organizationRepository.SingleOrDefaultAsync(p => p.Id == orgId); if (corporation == null || orgInfo == null) { throw new BusinessException($"系统中不存在OrgId为{orgId}的企业信息"); } var children = await _organizationRepository.GetAllAsync(p => p.ParentId == orgInfo.Id); if (children.Any()) { throw new BusinessException($"请先删除子公司信息"); } var departments = await _departmentRepository.GetAllAsync(p => p.OrgId == orgInfo.Id); if (departments.Any()) { throw new BusinessException($"请先删除该公司的部门信息"); } var corporationUsers = await GetService<IUserAppService>().GetOrgUser(orgInfo.Id,true); await UnitOfWorkAsync(async (conn, trans) => { await _organizationRepository.DeleteAsync(p => p.Id == orgInfo.Id,conn,trans); await _corporationRepository.DeleteAsync(p => p.OrgId == orgInfo.Id, conn, trans); foreach (var corporationUser in corporationUsers) { if (!await GetService<IUserAppService>().ResetUserOrgInfo(corporationUser.Id)) { throw new BusinessException("重置该公司部门员工部门信息失败,请稍后重试"); } } }, Connection); }
public async Task DeleteByUserId(long userId) { await UnitOfWorkAsync(async (conn, trans) => { await _userRepository.DeleteAsync(p => p.Id == userId, conn, trans); await _userRoleRepository.DeleteAsync(p => p.UserId == userId, conn, trans); await _userGroupRelationRepository.DeleteAsync(p => p.UserId == userId, conn, trans); }, Connection); }
public async Task Delete(long id) { using (var locker = await _lockerProvider.CreateLockAsync("DeleteUser")) { await locker.Lock(async() => { await UnitOfWorkAsync(async(conn, trans) => { await _userRepository.DeleteAsync(p => p.Id == id, conn, trans); await _userRoleRepository.DeleteAsync(p => p.UserId == id, conn, trans); await _userUserGroupRelationRepository.DeleteAsync(p => p.UserId == id, conn, trans); // todo: 删除其他关联表 }, Connection); }); } }
public async Task DeleteWordbook(long id) { var wordbook = await _wordbookRepository.SingleOrDefaultAsync(p => p.Id == id); if (wordbook == null) { throw new BusinessException($"系统中不存在Id为{id}的字典类型"); } if (wordbook.IsSysPreset) { throw new BusinessException($"不允许删除系统预设的字典类型"); } await UnitOfWorkAsync(async (conn, trans) => { await _wordbookRepository.DeleteAsync(wordbook, conn, trans); await _wordbookItemRepository.DeleteAsync(p => p.WordbookId == id, conn, trans); }, Connection); }
public async Task DeletePosition(long id) { var position = await _positionRepository.SingleOrDefaultAsync(p => p.Id == id); if (position == null) { throw new BusinessException($"不存在Id为{id}的职位信息"); } await _positionRepository.DeleteAsync(position); }
public async Task Delete(long id) { var userGroup = await _userGroupRepository.SingleOrDefaultAsync(p => p.Id == id); if (userGroup == null) { throw new BusinessException($"不存在Id为{id}的用户组信息"); } var children = await _userGroupRepository.GetAllAsync(p => p.ParentId == id); if (children.Any()) { throw new BusinessException("请先删除子用户组"); } await UnitOfWorkAsync(async (conn, trans) => { await _userGroupRepository.DeleteAsync(p => p.Id == id, conn, trans); await _userGroupRoleRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); await _userUserGroupRelationRepository.DeleteAsync(p => p.UserGroupId == id, conn, trans); }, Connection); }
public async Task Delete(long permissionId) { var operation = await _operationRepository.SingleOrDefaultAsync(p => p.PermissionId == permissionId); if (operation == null) { throw new BusinessException($"不存在permissionId为{permissionId}的操作信息"); } using (var locker = await _lockerProvider.CreateLockAsync("DeleteOperation")) { await locker.Lock(async() => { await UnitOfWorkAsync(async(conn, trans) => { await _operationRepository.DeleteAsync(p => p.PermissionId == permissionId, conn, trans); await _operationActionRepository.DeleteAsync(p => p.OperationId == operation.Id, conn, trans); await _permissionRepository.DeleteAsync(p => p.Id == operation.PermissionId, conn, trans); }, Connection); }); } }
public async Task <string> Delete(long id) { var tenant = await _tenantRepository.SingleOrDefaultAsync(p => p.Id == id); if (tenant == null) { throw new BusinessException($"不存在Id为{id}的租户信息"); } await _tenantRepository.DeleteAsync(p => p.Id == id); return("租户删除成功"); }
public async Task DeleteRoleById(long roleId) { var roleUserCount = await _userRoleRepository.GetCountAsync(p => p.RoleId == roleId); if (roleUserCount > 0) { throw new BusinessException("该角色被分配有用户,请先删除用户后再尝试"); } await UnitOfWorkAsync(async (conn, trans) => { await _roleRepository.DeleteAsync(p => p.Id == roleId, conn, trans); await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleId, conn, trans); }, Connection); }
public async Task Delete(long roleid) { var role = await _roleRepository.SingleOrDefaultAsync(p => p.Id == roleid); if (role == null) { throw new BusinessException($"不存在Id为{roleid}的角色信息"); } _session.CheckLoginUserDataPermision(role.DataPermissionType, "您设置的角色的数据权限大于您拥有数据权限,系统不允许该操作"); var userRoleCount = await _userRoleRepository.GetCountAsync(p => p.RoleId == roleid); if (userRoleCount > 0) { throw new BusinessException($"{role.Name}被分配用户,请先删除相关授权的用户信息"); } var userGroupRoleCount = await _userGroupRoleRepository.GetCountAsync(p => p.RoleId == roleid); if (userGroupRoleCount > 0) { throw new BusinessException($"{role.Name}被分配用户组,请先删除相关授权的用户组信息"); } using (var locker = await _lockerProvider.CreateLockAsync("DeleteRole")) { await locker.Lock(async() => { await UnitOfWorkAsync(async(conn, trans) => { await _roleRepository.DeleteAsync(p => p.Id == roleid, conn, trans); await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans); await _roleDataPermissionOrgRelationRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans); await _roleOrganizationRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans); await RemoveRoleCheckPemissionCache(roleid); }, Connection); }); } }
public async Task UpdateOperation(Permission operation, IEnumerable <long> functionIds) { await UnitOfWorkAsync(async (conn, trans) => { await _permissionRepository.UpdateAsync(operation, conn, trans); await _permissionFunctionRepository.DeleteAsync(p => p.PermissionId == operation.Id, conn, trans); foreach (var funcId in functionIds) { var permissionFunc = new PermissionFunction() { FunctionId = funcId, PermissionId = operation.Id, }; await _permissionFunctionRepository.InsertAsync(permissionFunc, conn, trans); } }, Connection); }
public async Task DeleteUserGroupById(long userGroupId) { var userGroupchildrenCount = await _userGroupRepository.GetCountAsync(p => p.ParentId == userGroupId); if (userGroupchildrenCount > 0) { throw new BusinessException("要删除的用户组存在子节点,请先删除子用户组"); } var deleteUserGroupRoleCount = await _userGroupRoleRepository.GetCountAsync(p => p.UserGroupId == userGroupId); if (deleteUserGroupRoleCount > 0) { throw new BusinessException("要删除的用户组分配了角色,无法删除,请先取消角色授权"); } await UnitOfWorkAsync(async (conn, trans) => { await _userGroupRepository.DeleteAsync(p => p.Id == userGroupId, conn, trans); await _userGroupRelationRepository.DeleteAsync(p => p.UserGroupId == userGroupId, conn, trans); }, Connection); }
public async Task DeleteMenu(long id) { var menu = await _menuRepository.GetAsync(id); var childrenMenus = await _menuRepository.GetAllAsync(p => p.ParentId == id); if (childrenMenus.Any()) { throw new BusinessException("存在子菜单,请先删除子菜单"); } var rolePermissions = await _rolePermissionRepository.GetAllAsync(p => p.PerssionId == menu.PermissionId); if (rolePermissions.Any()) { throw new BusinessException("该菜单被分配给角色,请先删除关系后再尝试"); } await UnitOfWorkAsync(async (conn, trans) => { await _permissionRepository.DeleteAsync(p => p.Id == menu.PermissionId, conn, trans); await _menuRepository.DeleteAsync(menu, conn, trans); }, Connection); }
public async Task <long> Create(CreateRoleInput input, long?tenantId = null) { using (var locker = await _lockerProvider.CreateLockAsync("CreateRole")) { return(await locker.Lock(async() => { var exsitRole = await _roleRepository.FirstOrDefaultAsync(p => p.Identification == input.Identification, false); if (exsitRole != null) { throw new BusinessException($"系统中已经存在{input.Identification}的角色"); } CheckUserDefinedDataPermission(input.DataPermissionType, input.DataPermissionOrgIds); var role = input.MapTo <Role>(); role.TenantId = _session.TenantId; if (tenantId.HasValue) { role.TenantId = tenantId.Value; } await UnitOfWorkAsync(async(conn, trans) => { var roleId = await _roleRepository.InsertAndGetIdAsync(role, conn, trans); await _rolePermissionRepository.DeleteAsync(p => p.RoleId == role.Id, conn, trans); var insertSql = "INSERT INTO RolePermission(PermissionId,RoleId,CreateTime,CreateBy,TenantId) VALUES(@PermissionId,@RoleId,@CreationTime,@CreatorUserId,@TenantId)"; var rolePermissions = new List <RolePermission>(); foreach (var permissionId in input.PermissionIds) { rolePermissions.Add(new RolePermission { PermissionId = permissionId, RoleId = roleId, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = role.TenantId }); } await conn.ExecuteAsync(insertSql, rolePermissions, trans); if (!input.IsAllOrg) { foreach (var orgId in input.OrgIds) { var roleOrg = new RoleOrganization() { RoleId = roleId, OrgId = orgId, TenantId = role.TenantId }; await _roleOrganizationRepository.InsertAsync(roleOrg, conn, trans); } } if (input.DataPermissionType == DataPermissionType.UserDefined) { var insertDataPermissionOrgSql = "INSERT INTO RoleDataPermissionOrgRelation(RoleId,OrgId,CreateTime,CreateBy,TenantId) VALUES(@RoleId,@OrgId,@CreationTime,@CreatorUserId,@TenantId)"; var dataPermissionOrgDatas = new List <RoleDataPermissionOrgRelation>(); foreach (var orgId in input.DataPermissionOrgIds) { dataPermissionOrgDatas.Add(new RoleDataPermissionOrgRelation() { RoleId = roleId, OrgId = orgId, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = role.TenantId }); } await conn.ExecuteAsync(insertDataPermissionOrgSql, dataPermissionOrgDatas, trans); } }, Connection); return role.Id; })); } }
public async virtual Task <bool> Delete(TDeleteInput input) { return(await Repository.DeleteAsync(input.Id)); }
public async Task <string> DeleteFunction(DeleteByIdInput input) { await _functionRepository.DeleteAsync(p => p.Id == input.Id); return("删除功能操作成功"); }
public async Task DeleteAsync(TEntity entity) { await _dapperRepository.DeleteAsync(entity); }
public async Task Update(UpdateUserGroupInput input) { CheckUserDefinedDataPermission(input.DataPermissionType, input.DataPermissionOrgIds); using (var locker = await _lockerProvider.CreateLockAsync("UpdateUserGroup")) { await locker.Lock(async() => { var userGroup = await _userGroupRepository.SingleOrDefaultAsync(p => p.Id == input.Id); if (userGroup == null) { throw new BusinessException($"不存在Id为{input.Id}的用户组"); } if (!userGroup.Identification.Equals(input.Identification)) { var exsitUserGroup = await _userGroupRepository.FirstOrDefaultAsync(p => p.Identification == input.Identification, false); if (exsitUserGroup != null) { throw new BusinessException($"系统中已经存在{input.Identification}的用户组"); } } userGroup = input.MapTo(userGroup); await UnitOfWorkAsync(async(conn, trans) => { var userGroupOrganizationIds = (await _userGroupOrganizationRepository.GetAllAsync(p => p.UserGroupId == userGroup.Id, conn, trans)).Select(p => p.OrgId).ToArray(); await _userGroupRepository.UpdateAsync(userGroup, conn, trans); await _userGroupRoleRepository.DeleteAsync(p => p.UserGroupId == userGroup.Id, conn, trans); await _userGroupPermissionRepository.DeleteAsync(p => p.UserGroupId == userGroup.Id, conn, trans); await _userGroupDataPermissionOrgRelationRepository.DeleteAsync( p => p.UserGroupId == userGroup.Id, conn, trans); await _userGroupOrganizationRepository.DeleteAsync(p => p.UserGroupId == userGroup.Id, conn, trans); foreach (var roleId in input.RoleIds) { await _userGroupRoleRepository.InsertAsync( new UserGroupRole { UserGroupId = userGroup.Id, RoleId = roleId }, conn, trans); } if (!input.IsAllOrg) { if (!await UpdateOrgIdsEqExistOrgIds(input.OrgIds, userGroupOrganizationIds, userGroup.Id)) { throw new BusinessException("用户组所属类型为自定义的且已经存在用户的,不允许修改用户组的所属部门"); } foreach (var orgId in input.OrgIds) { var userGroupOrg = new UserGroupOrganization() { UserGroupId = userGroup.Id, OrgId = orgId }; await _userGroupOrganizationRepository.InsertAsync(userGroupOrg, conn, trans); } } var insertSql = "INSERT INTO UserGroupPermission(PermissionId,UserGroupId,CreateTime,CreateBy,TenantId) VALUES(@PermissionId,@UserGroupId,@CreationTime,@CreatorUserId,@TenantId)"; var userGroupPermissions = new List <UserGroupPermission>(); foreach (var permissionId in input.PermissionIds) { userGroupPermissions.Add(new UserGroupPermission { PermissionId = permissionId, UserGroupId = userGroup.Id, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = _session.TenantId }); } await conn.ExecuteAsync(insertSql, userGroupPermissions, trans); if (input.DataPermissionType == DataPermissionType.UserDefined) { var insertDataPermissionOrgSql = "INSERT INTO UserGroupDataPermissionOrgRelation(UserGroupId,OrgId,CreateTime,CreateBy,TenantId) VALUES(@UserGroupId,@OrgId,@CreationTime,@CreatorUserId,@TenantId)"; var dataPermissionOrgDatas = new List <UserGroupDataPermissionOrgRelation>(); foreach (var orgId in input.DataPermissionOrgIds) { dataPermissionOrgDatas.Add(new UserGroupDataPermissionOrgRelation() { UserGroupId = userGroup.Id, OrgId = orgId, CreationTime = DateTime.Now, CreatorUserId = _session.UserId, TenantId = _session.TenantId }); } await conn.ExecuteAsync(insertDataPermissionOrgSql, dataPermissionOrgDatas, trans); } await RemoveUserGroupCheckPemissionCache(userGroup.Id); }, Connection); }); } }
public async Task <int> DeleteAsync(Table entity) { return(await _dapperRepository.DeleteAsync(entity)); }
public Task DeleteBookById(Book book) { return(_bookDapperRepository.DeleteAsync(book)); }
public async Task Dapper_Repository_Tests() { using (IUnitOfWorkCompleteHandle uow = _unitOfWorkManager.Begin()) { //---Insert operation should work and tenant, creation audit properties must be set--------------------- await _productDapperRepository.InsertAsync(new Product("TShirt")); Product insertedProduct = await _productDapperRepository.FirstOrDefaultAsync(x => x.Name == "TShirt"); insertedProduct.ShouldNotBeNull(); insertedProduct.TenantId.ShouldBe(AbpSession.TenantId); ((DateTime?)insertedProduct.CreationTime).ShouldNotBe(null); insertedProduct.CreatorUserId.ShouldBe(AbpSession.UserId); //----Update operation should work and Modification Audits should be set--------------------------- await _productDapperRepository.InsertAsync(new Product("TShirt")); Product productToUpdate = await _productDapperRepository.FirstOrDefaultAsync(x => x.Name == "TShirt"); productToUpdate.Name = "Pants"; await _productDapperRepository.UpdateAsync(productToUpdate); productToUpdate.ShouldNotBeNull(); productToUpdate.TenantId.ShouldBe(AbpSession.TenantId); ((DateTime?)productToUpdate.CreationTime).ShouldNotBe(null); productToUpdate.LastModifierUserId.ShouldBe(AbpSession.UserId); //---Get method should return single------------------------------------------------------------------- await _productDapperRepository.InsertAsync(new Product("TShirt")); Action getAction = () => _productDapperRepository.Single(x => x.Name == "TShirt"); getAction.ShouldThrow <InvalidOperationException>("Sequence contains more than one element"); //----Select * from syntax should work--------------------------------- var queryResult = await _productDapperRepository.QueryAsync("select * from Products"); IEnumerable <Product> products = queryResult; products.Count().ShouldBeGreaterThan(0); //------------Ef and Dapper should work under same transaction--------------------- Product productFromEf = await _productRepository.FirstOrDefaultAsync(x => x.Name == "TShirt"); Product productFromDapper = await _productDapperRepository.SingleAsync(productFromEf.Id); productFromDapper.Name.ShouldBe(productFromEf.Name); productFromDapper.TenantId.ShouldBe(productFromEf.TenantId); //------Soft Delete should work for Dapper-------------- await _productDapperRepository.InsertAsync(new Product("SoftDeletableProduct")); Product toSoftDeleteProduct = await _productDapperRepository .SingleAsync(x => x.Name == "SoftDeletableProduct"); await _productDapperRepository.DeleteAsync(toSoftDeleteProduct); toSoftDeleteProduct.IsDeleted.ShouldBe(true); toSoftDeleteProduct.DeleterUserId.ShouldBe(AbpSession.UserId); toSoftDeleteProduct.TenantId.ShouldBe(AbpSession.TenantId); Product softDeletedProduct = await _productRepository .FirstOrDefaultAsync(x => x.Name == "SoftDeletableProduct"); softDeletedProduct.ShouldBeNull(); Product softDeletedProductFromDapper = await _productDapperRepository .FirstOrDefaultAsync(x => x.Name == "SoftDeletableProduct"); softDeletedProductFromDapper.ShouldBeNull(); using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete)) { Product softDeletedProductWhenFilterDisabled = await _productRepository .FirstOrDefaultAsync(x => x.Name == "SoftDeletableProduct"); softDeletedProductWhenFilterDisabled.ShouldNotBeNull(); Product softDeletedProductFromDapperWhenFilterDisabled = await _productDapperRepository .SingleAsync(x => x.Name == "SoftDeletableProduct"); softDeletedProductFromDapperWhenFilterDisabled.ShouldNotBeNull(); } using (AbpSession.Use(2, 266)) { int productWithTenant2Id = await _productDapperRepository .InsertAndGetIdAsync(new Product("ProductWithTenant2")); var productWithTenant2 = await _productRepository.GetAsync(productWithTenant2Id); productWithTenant2.TenantId .ShouldBe(1); //Not sure about that?,Because we changed TenantId to 2 in this scope !!! Abp.TenantId = 2 now NOT 1 !!! } using (_unitOfWorkManager.Current.SetTenantId(3)) { int productWithTenant3Id = await _productDapperRepository .InsertAndGetIdAsync(new Product("ProductWithTenant3")); Product productWithTenant3 = await _productRepository.GetAsync(productWithTenant3Id); productWithTenant3.TenantId.ShouldBe(3); } Product productWithTenantId3FromDapper = await _productDapperRepository .FirstOrDefaultAsync(x => x.Name == "ProductWithTenant3"); productWithTenantId3FromDapper.ShouldBeNull(); Product p = await _productDapperRepository.FirstOrDefaultAsync(x => x.Status == Status.Active); p.ShouldNotBeNull(); using (_unitOfWorkManager.Current.SetTenantId(3)) { Product productWithTenantId3FromDapperInsideTenantScope = await _productDapperRepository .FirstOrDefaultAsync(x => x.Name == "ProductWithTenant3"); productWithTenantId3FromDapperInsideTenantScope.ShouldNotBeNull(); } //About issue-#2091 using (_unitOfWorkManager.Current.SetTenantId(AbpSession.TenantId)) { int productWithTenantId40 = await _productDapperRepository .InsertAndGetIdAsync(new Product("ProductWithTenantId40")); Product productWithTenant40 = await _productRepository.GetAsync(productWithTenantId40); productWithTenant40.TenantId.ShouldBe(AbpSession.TenantId); productWithTenant40.CreatorUserId.ShouldBe(AbpSession.UserId); } //Second DbContext tests var productDetailId = await _productDetailRepository .InsertAndGetIdAsync(new ProductDetail("Woman")); (await _productDetailDapperRepository.GetAsync(productDetailId)).ShouldNotBeNull(); await uow.CompleteAsync(); } }