diff --git a/NewLife.CubeNC/Areas/Admin/Controllers/TenantController.cs b/NewLife.CubeNC/Areas/Admin/Controllers/TenantController.cs
index 8c1e0f1c..b5e8046c 100644
--- a/NewLife.CubeNC/Areas/Admin/Controllers/TenantController.cs
+++ b/NewLife.CubeNC/Areas/Admin/Controllers/TenantController.cs
@@ -78,4 +78,55 @@ protected override Boolean Valid(Tenant entity, DataObjectMethodType type, Boole
return base.Valid(entity, type, post);
}
+
+ ///
+ ///
+ ///
+ protected override Int32 OnInsert(Tenant entity)
+ {
+ var result = base.OnInsert(entity);
+
+ var tuEntity = TenantUser.FindByTenantIdAndUserId(entity.Id, entity.ManagerId);
+ tuEntity ??= new TenantUser()
+ {
+ TenantId = entity.Id,
+ UserId = entity.ManagerId
+ };
+
+ tuEntity.Enable = true;
+ tuEntity.RoleIds = entity.RoleIds;
+
+ tuEntity.Save();
+
+ return result;
+ }
+
+ ///
+ ///
+ ///
+ protected override Int32 OnUpdate(Tenant entity)
+ {
+ var oldTenantEntity = Tenant.FindById(entity.Id);
+ var tuEntity = TenantUser.FindByTenantIdAndUserId(oldTenantEntity.Id, oldTenantEntity.ManagerId);
+
+ if (entity.ManagerId != oldTenantEntity.ManagerId)
+ {
+ tuEntity.Enable = false;
+ tuEntity.Save();
+ }
+
+ var newTuEntity = TenantUser.FindByTenantIdAndUserId(entity.Id, entity.ManagerId);
+ newTuEntity ??= new TenantUser()
+ {
+ TenantId = entity.Id,
+ UserId = entity.ManagerId
+ };
+
+ newTuEntity.Enable = entity.Enable;
+ newTuEntity.RoleIds = entity.RoleIds;
+
+ newTuEntity.Save();
+
+ return base.OnUpdate(entity);
+ }
}
\ No newline at end of file
diff --git a/NewLife.CubeNC/Views/layui/_Navbar.cshtml b/NewLife.CubeNC/Views/layui/_Navbar.cshtml
index 35830362..0a010ec4 100644
--- a/NewLife.CubeNC/Views/layui/_Navbar.cshtml
+++ b/NewLife.CubeNC/Views/layui/_Navbar.cshtml
@@ -45,20 +45,9 @@
@if (set.EnableTenant && user != null)
{
- var tList = TenantUser.FindAllByUserId(user.ID);
- // 创建租户或修改租户管理员时,会自动添加租户管理员到租户用户表,所以这里不需要再添加
- // var tManager = Tenant.FindByManagerId(user.ID);
- // if (tManager != null)
- // {
- // tList.Add(new TenantUser()
- // {
- // TenantId = tManager.Id,
- // UserId = user.ID
- // });
- // }
-
+ var tList = TenantUser.FindAllByUserId(user.ID).Where(e => e.Tenant.Enable);
var tenant = XCode.Membership.Tenant.FindById(TenantContext.CurrentId);
- var tenantName = tenant?.Name;
+ var tenantName = tenant == null ? null : tenant.Enable ? tenant.Name : null;