157 lines
5.2 KiB
Plaintext
157 lines
5.2 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 class="control-label">Name: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Title" class="control-label">Database Type: </label>
|
|
</td>
|
|
<td>
|
|
<select class="custom-select" @bind="@type">
|
|
<option value="LocalDB">Local Database</option>
|
|
<option value="SQLServer">SQL Server</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Title" class="control-label">Server: </label>
|
|
</td>
|
|
<td>
|
|
<input type="text" class="form-control" @bind="@server" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Title" class="control-label">Database: </label>
|
|
</td>
|
|
<td>
|
|
<input type="text" class="form-control" @bind="@database" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Title" class="control-label">Integrated Security: </label>
|
|
</td>
|
|
<td>
|
|
<select 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="Title" class="control-label">Username: </label>
|
|
</td>
|
|
<td>
|
|
<input type="text" class="form-control" @bind="@username" />
|
|
</td>
|
|
</tr>
|
|
<tr style="@integratedsecurity">
|
|
<td>
|
|
<label for="Title" class="control-label">Password: </label>
|
|
</td>
|
|
<td>
|
|
<input 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);
|
|
}
|
|
}
|
|
}
|