157 lines
5.5 KiB
Plaintext
157 lines
5.5 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Tenants
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject ITenantService TenantService
|
|
@inject IInstallationService InstallationService
|
|
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<Label For="name" HelpText="Enter the name for the tenant">Name: </Label>
|
|
</td>
|
|
<td>
|
|
<input id="name" class="form-control" @bind="@name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<Label For="databaseType" HelpText="Select the database type for the tenant">Database Type: </Label>
|
|
</td>
|
|
<td>
|
|
<select id="databaseType" class="custom-select" @bind="@type">
|
|
<option value="LocalDB">Local Database</option>
|
|
<option value="SQLServer">SQL Server</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<Label For="server" HelpText="Enter the server for the tenant">Server: </Label>
|
|
</td>
|
|
<td>
|
|
<input id="server" type="text" class="form-control" @bind="@server" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<Label For="database" HelpText="Enter the database for the tenant">Database: </Label>
|
|
</td>
|
|
<td>
|
|
<input id="database" type="text" class="form-control" @bind="@database" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<Label For="integratedSecurity" HelpText="Select if you want integrated security or not">Integrated Security: </Label>
|
|
</td>
|
|
<td>
|
|
<select id="integratedSecurity" class="custom-select" @onchange="SetIntegratedSecurity">
|
|
<option value="true" selected>True</option>
|
|
<option value="false">False</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr style="@integratedsecurity">
|
|
<td>
|
|
<Label For="username" HelpText="Enter the username for the integrated security">Username: </Label>
|
|
</td>
|
|
<td>
|
|
<input id="username" type="text" class="form-control" @bind="@username" />
|
|
</td>
|
|
</tr>
|
|
<tr style="@integratedsecurity">
|
|
<td>
|
|
<Label For="password" HelpText="Enter the password for the integrated security">Password: </Label>
|
|
</td>
|
|
<td>
|
|
<input id="password" type="password" class="form-control" @bind="@password" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<button type="button" class="btn btn-success" @onclick="SaveTenant">Save</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
|
|
|
@code {
|
|
private string name = string.Empty;
|
|
private string type = "LocalDB";
|
|
private string server = "(LocalDb)\\MSSQLLocalDB";
|
|
private string database = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
|
|
private string username = string.Empty;
|
|
private string password = string.Empty;
|
|
private string schema = string.Empty;
|
|
private string integratedsecurity = "display: none;";
|
|
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Host;
|
|
|
|
private void SetIntegratedSecurity(ChangeEventArgs e)
|
|
{
|
|
if (Convert.ToBoolean((string)e.Value))
|
|
{
|
|
integratedsecurity = "display: none;";
|
|
}
|
|
else
|
|
{
|
|
integratedsecurity = string.Empty;
|
|
}
|
|
}
|
|
|
|
private async Task SaveTenant()
|
|
{
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
ShowProgressIndicator();
|
|
|
|
var connectionString = string.Empty;
|
|
if (type == "LocalDB")
|
|
{
|
|
connectionString = "Data Source=" + server + ";AttachDbFilename=|DataDirectory|\\" + database + ".mdf;Initial Catalog=" + database + ";Integrated Security=SSPI;";
|
|
}
|
|
else
|
|
{
|
|
connectionString = "Data Source=" + server + ";Initial Catalog=" + database + ";";
|
|
|
|
if (integratedsecurity == "display: none;")
|
|
{
|
|
connectionString += "Integrated Security=SSPI;";
|
|
}
|
|
else
|
|
{
|
|
connectionString += "User ID=" + username + ";Password=" + password;
|
|
|
|
}
|
|
}
|
|
|
|
var config = new InstallConfig
|
|
{
|
|
IsMaster = false,
|
|
ConnectionString = connectionString,
|
|
};
|
|
|
|
var installation = await InstallationService.Install(config);
|
|
if (installation.Success)
|
|
{
|
|
//TODO : Move to Database Manager
|
|
var tenant = new Tenant
|
|
{
|
|
Name = name,
|
|
DBConnectionString = connectionString,
|
|
IsInitialized = false
|
|
};
|
|
await TenantService.AddTenantAsync(tenant);
|
|
await logger.LogInformation("Tenant Created {Tenant}", tenant);
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
else
|
|
{
|
|
await logger.LogError("Error Creating Tenant {Error}", installation.Message);
|
|
AddModuleMessage(installation.Message, MessageType.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage("You Must Provide A Name For The Tenant", MessageType.Warning);
|
|
}
|
|
}
|
|
}
|