From da234c661e0c93934deb1dbe7d09458609933133 Mon Sep 17 00:00:00 2001 From: xiyunfei Date: Sat, 2 Sep 2023 00:15:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=A7=9F=E6=88=B7=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=95=8C=E9=9D=A2=E7=A7=9F=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E6=96=B0=E5=A2=9E/=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E6=97=B6=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Controllers/TenantController.cs | 51 +++++++++++++++++++ NewLife.CubeNC/Views/layui/_Navbar.cshtml | 15 +----- 2 files changed, 53 insertions(+), 13 deletions(-) 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;