mirror of https://github.com/abpframework/abp.git
11 changed files with 203 additions and 15 deletions
@ -1,10 +1,16 @@ |
|||||
using System; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Services; |
using Volo.Abp.Application.Services; |
||||
|
|
||||
namespace Volo.Abp.TenantManagement |
namespace Volo.Abp.TenantManagement |
||||
{ |
{ |
||||
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, Guid, GetTenantsInput, TenantCreateDto, TenantUpdateDto> |
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, Guid, GetTenantsInput, TenantCreateDto, TenantUpdateDto> |
||||
{ |
{ |
||||
//TODO: Manage connection strings
|
Task<string> GetDefaultConnectionStringAsync(Guid id); |
||||
|
|
||||
|
Task SetDefaultConnectionStringAsync(Guid id, string defaultConnectionString); |
||||
|
|
||||
|
Task RemoveDefaultConnectionStringAsync(Guid id); |
||||
|
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,11 +1,14 @@ |
|||||
{ |
{ |
||||
"culture": "zh-Hans", |
"culture": "zh-Hans", |
||||
"texts": { |
"texts": { |
||||
"Menu:TenantManagement": "租户管理", |
"Menu:TenantManagement": "租户管理", |
||||
"Tenants": "租户", |
"Tenants": "租户", |
||||
"NewTenant": "新租户", |
"NewTenant": "新租户", |
||||
"TenantName": "租户名称", |
"TenantName": "租户名称", |
||||
"DisplayName:TenantName": "租户名称", |
"DisplayName:TenantName": "租户名称", |
||||
"TenantDeletionConfirmationMessage": "租户 '{0}' 将被删除. 你确定吗?" |
"TenantDeletionConfirmationMessage": "租户 '{0}' 将被删除. 你确定吗?", |
||||
} |
"ConnectionStrings": "连接字符串", |
||||
} |
"DisplayName:DefaultConnectionString": "默认连接字符串", |
||||
|
"DisplayName:UseSharedDatabase": "使用共享数据库" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
@page |
||||
|
@using Microsoft.Extensions.Localization |
||||
|
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal |
||||
|
@using Volo.Abp.TenantManagement.Localization |
||||
|
@using Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants |
||||
|
@model ConnectionStringsModal |
||||
|
@inject IStringLocalizer<AbpTenantManagementResource> L |
||||
|
@{ |
||||
|
Layout = null; |
||||
|
} |
||||
|
<form method="post" asp-page="/TenantManagement/Tenants/ConnectionStringsModal"> |
||||
|
<abp-modal> |
||||
|
<abp-modal-header title="@L["ConnectionStrings"]"></abp-modal-header> |
||||
|
<abp-modal-body> |
||||
|
<abp-input asp-for="Tenant.Id"></abp-input> |
||||
|
|
||||
|
<abp-input asp-for="Tenant.UseSharedDatabase"></abp-input> |
||||
|
|
||||
|
<div id="Tenant_DefaultConnectionString_Wrap" class="@(Model.Tenant.UseSharedDatabase ? "d-none" : "")" > |
||||
|
<abp-input asp-for="Tenant.DefaultConnectionString"></abp-input> |
||||
|
</div> |
||||
|
|
||||
|
</abp-modal-body> |
||||
|
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer> |
||||
|
</abp-modal> |
||||
|
</form> |
||||
|
|
||||
|
<script> |
||||
|
|
||||
|
$("#Tenant_UseSharedDatabase").change(function() { |
||||
|
$("#Tenant_DefaultConnectionString_Wrap").toggleClass("d-none"); |
||||
|
$(this).val($(this).prop("checked")); |
||||
|
}); |
||||
|
|
||||
|
</script> |
||||
@ -0,0 +1,62 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; |
||||
|
|
||||
|
namespace Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants |
||||
|
{ |
||||
|
public class ConnectionStringsModal : AbpPageModel |
||||
|
{ |
||||
|
[BindProperty] |
||||
|
public TenantInfoModel Tenant { get; set; } |
||||
|
|
||||
|
private readonly ITenantAppService _tenantAppService; |
||||
|
|
||||
|
public ConnectionStringsModal(ITenantAppService tenantAppService) |
||||
|
{ |
||||
|
_tenantAppService = tenantAppService; |
||||
|
} |
||||
|
|
||||
|
public async Task OnGetAsync(Guid id) |
||||
|
{ |
||||
|
var defaultConnectionString = await _tenantAppService.GetDefaultConnectionStringAsync(id); |
||||
|
Tenant = new TenantInfoModel() |
||||
|
{ |
||||
|
Id = id, |
||||
|
DefaultConnectionString = defaultConnectionString, |
||||
|
UseSharedDatabase = defaultConnectionString.IsNullOrWhiteSpace() |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public async Task<IActionResult> OnPostAsync() |
||||
|
{ |
||||
|
ValidateModel(); |
||||
|
|
||||
|
if (Tenant.UseSharedDatabase || Tenant.DefaultConnectionString.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
await _tenantAppService.RemoveDefaultConnectionStringAsync(Tenant.Id); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
await _tenantAppService.SetDefaultConnectionStringAsync(Tenant.Id, Tenant.DefaultConnectionString); |
||||
|
} |
||||
|
|
||||
|
return NoContent(); |
||||
|
} |
||||
|
|
||||
|
public class TenantInfoModel |
||||
|
{ |
||||
|
[HiddenInput] |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
[Display(Name = "DisplayName:UseSharedDatabase")] |
||||
|
public bool UseSharedDatabase { get; set; } |
||||
|
|
||||
|
[StringLength(TenantConnectionStringConsts.MaxNameLength)] |
||||
|
[Display(Name = "DisplayName:DefaultConnectionString")] |
||||
|
public string DefaultConnectionString { get; set; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue