refactored site management to include better support for multi-tenancy
This commit is contained in:
parent
0405a2ab36
commit
06257943ca
|
@ -154,10 +154,6 @@
|
|||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, Constants.HostRole))
|
||||
{
|
||||
<ActionDialog Header="Delete Site" Message="@("Are You Sure You Wish To Delete This Site?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite())" />
|
||||
}
|
||||
<br />
|
||||
<br />
|
||||
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon" DeletedBy="@deletedby" DeletedOn="@deletedon"></AuditInfo>
|
||||
|
@ -202,7 +198,7 @@
|
|||
{
|
||||
Themes = await ThemeService.GetThemesAsync();
|
||||
aliases = await AliasService.GetAliasesAsync();
|
||||
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
||||
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId, PageState.Alias);
|
||||
if (site != null)
|
||||
{
|
||||
name = site.Name;
|
||||
|
@ -275,7 +271,17 @@
|
|||
{
|
||||
if (name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
||||
{
|
||||
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
||||
bool unique = true;
|
||||
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (aliases.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId))
|
||||
{
|
||||
unique = false;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
{
|
||||
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId, PageState.Alias);
|
||||
if (site != null)
|
||||
{
|
||||
site.Name = name;
|
||||
|
@ -290,11 +296,11 @@
|
|||
site.DefaultContainerType = containertype;
|
||||
site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
||||
|
||||
site = await SiteService.UpdateSiteAsync(site);
|
||||
site = await SiteService.UpdateSiteAsync(site, PageState.Alias);
|
||||
|
||||
urls = urls.Replace("\n", ",");
|
||||
string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (Alias alias in aliases)
|
||||
foreach (Alias alias in aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
||||
{
|
||||
if (!names.Contains(alias.Name))
|
||||
{
|
||||
|
@ -327,6 +333,11 @@
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning);
|
||||
}
|
||||
|
@ -337,19 +348,4 @@
|
|||
AddModuleMessage("Error Saving Site", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteSite()
|
||||
{
|
||||
try
|
||||
{
|
||||
await SiteService.DeleteSiteAsync(PageState.Site.SiteId);
|
||||
await logger.LogInformation("Sited Deleted {SiteId}", PageState.Site.SiteId);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Deleting Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
||||
AddModuleMessage("Error Deleting Site", MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,6 +186,17 @@ else
|
|||
private async Task SaveSite()
|
||||
{
|
||||
if (tenantid != "-1" && name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
||||
{
|
||||
bool unique = true;
|
||||
List<Alias> aliases = await AliasService.GetAliasesAsync();
|
||||
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (aliases.Exists(item => item.Name == name))
|
||||
{
|
||||
unique = false;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
{
|
||||
bool isvalid = true;
|
||||
|
||||
|
@ -203,7 +214,7 @@ else
|
|||
{
|
||||
ShowProgressIndicator();
|
||||
|
||||
List<Alias> aliases = new List<Alias>();
|
||||
aliases = new List<Alias>();
|
||||
urls = urls.Replace("\n", ",");
|
||||
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
|
@ -247,7 +258,7 @@ else
|
|||
await TenantService.UpdateTenantAsync(tenant);
|
||||
}
|
||||
}
|
||||
await logger.LogInformation("Site Created {Site}", site);
|
||||
await Log(aliases[0], LogLevel.Information, "", null, "Site Created {Site}", site);
|
||||
|
||||
Uri uri = new Uri(NavigationManager.Uri);
|
||||
NavigationManager.NavigateTo(uri.Scheme + "://" + aliases[0].Name, true);
|
||||
|
@ -259,6 +270,11 @@ else
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("You Must Provide A Tenant, Site Name, Alias, And Default Theme/Container", MessageType.Warning);
|
||||
}
|
||||
|
|
265
Oqtane.Client/Modules/Admin/Sites/Edit.razor
Normal file
265
Oqtane.Client/Modules/Admin/Sites/Edit.razor
Normal file
|
@ -0,0 +1,265 @@
|
|||
@namespace Oqtane.Modules.Admin.Sites
|
||||
@inherits ModuleBase
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ISiteService SiteService
|
||||
@inject ITenantService TenantService
|
||||
@inject IAliasService AliasService
|
||||
@inject IThemeService ThemeService
|
||||
|
||||
@if (themes != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Name: </label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" @bind="@name" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Tenant: </label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" @bind="@tenant" readonly />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Aliases: </label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea class="form-control" @bind="@urls" rows="3" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Default Theme: </label>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control" @onchange="(e => ThemeChanged(e))">
|
||||
<option value=""><Select Theme></option>
|
||||
@foreach (KeyValuePair<string, string> item in themes)
|
||||
{
|
||||
if (item.Key == themetype)
|
||||
{
|
||||
<option value="@item.Key" selected>@item.Value</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@item.Key">@item.Value</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Default Layout: </label>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control" @bind="@layouttype">
|
||||
<option value=""><Select Layout></option>
|
||||
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
|
||||
{
|
||||
<option value="@panelayout.Key">@panelayout.Value</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Default Container: </label>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control" @bind="@containertype">
|
||||
<option value=""><Select Container></option>
|
||||
@foreach (KeyValuePair<string, string> container in containers)
|
||||
{
|
||||
<option value="@container.Key">@container.Value</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Is Deleted? </label>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control" @bind="@isdeleted">
|
||||
<option value="True">Yes</option>
|
||||
<option value="False">No</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||
<br />
|
||||
<br />
|
||||
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon" DeletedBy="@deletedby" DeletedOn="@deletedon"></AuditInfo>
|
||||
}
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
||||
|
||||
Dictionary<string, string> themes;
|
||||
Dictionary<string, string> panelayouts;
|
||||
Dictionary<string, string> containers;
|
||||
|
||||
Alias Alias;
|
||||
List<Theme> Themes;
|
||||
string name = "";
|
||||
List<Tenant> tenants;
|
||||
string tenant = "";
|
||||
List<Alias> aliases;
|
||||
string urls = "";
|
||||
string themetype;
|
||||
string layouttype;
|
||||
string containertype;
|
||||
|
||||
string createdby;
|
||||
DateTime createdon;
|
||||
string modifiedby;
|
||||
DateTime modifiedon;
|
||||
string deletedby;
|
||||
DateTime? deletedon;
|
||||
string isdeleted;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Themes = await ThemeService.GetThemesAsync();
|
||||
aliases = await AliasService.GetAliasesAsync();
|
||||
|
||||
Alias = aliases.Find(item => item.AliasId == Int32.Parse(PageState.QueryString["id"]));
|
||||
Site site = await SiteService.GetSiteAsync(Alias.SiteId, Alias);
|
||||
if (site != null)
|
||||
{
|
||||
name = site.Name;
|
||||
tenants = await TenantService.GetTenantsAsync();
|
||||
tenant = tenants.Find(item => item.TenantId == site.TenantId).Name;
|
||||
foreach (Alias alias in aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
||||
{
|
||||
urls += alias.Name + "\n";
|
||||
}
|
||||
themetype = site.DefaultThemeType;
|
||||
panelayouts = ThemeService.GetPaneLayoutTypes(Themes, themetype);
|
||||
layouttype = site.DefaultLayoutType;
|
||||
containertype = site.DefaultContainerType;
|
||||
|
||||
createdby = site.CreatedBy;
|
||||
createdon = site.CreatedOn;
|
||||
modifiedby = site.ModifiedBy;
|
||||
modifiedon = site.ModifiedOn;
|
||||
deletedby = site.DeletedBy;
|
||||
deletedon = site.DeletedOn;
|
||||
isdeleted = site.IsDeleted.ToString();
|
||||
}
|
||||
|
||||
themes = ThemeService.GetThemeTypes(Themes);
|
||||
containers = ThemeService.GetContainerTypes(Themes);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Log(Alias, LogLevel.Error, "", ex, "Error Loading Site {SiteId} {Error}", Alias.SiteId, ex.Message);
|
||||
AddModuleMessage(ex.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ThemeChanged(ChangeEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
themetype = (string)e.Value;
|
||||
if (themetype != "")
|
||||
{
|
||||
panelayouts = ThemeService.GetPaneLayoutTypes(Themes, themetype);
|
||||
}
|
||||
else
|
||||
{
|
||||
panelayouts = new Dictionary<string, string>();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message);
|
||||
AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveSite()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
|
||||
{
|
||||
bool unique = true;
|
||||
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (aliases.Exists(item => item.Name == name && item.SiteId != Alias.SiteId && item.TenantId != Alias.TenantId))
|
||||
{
|
||||
unique = false;
|
||||
}
|
||||
}
|
||||
if (unique)
|
||||
{
|
||||
Site site = await SiteService.GetSiteAsync(Alias.SiteId, Alias);
|
||||
if (site != null)
|
||||
{
|
||||
site.Name = name;
|
||||
site.LogoFileId = null;
|
||||
site.DefaultThemeType = themetype;
|
||||
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
|
||||
site.DefaultContainerType = containertype;
|
||||
site.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
||||
|
||||
site = await SiteService.UpdateSiteAsync(site, Alias);
|
||||
|
||||
urls = urls.Replace("\n", ",");
|
||||
string[] names = urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (Alias alias in aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
|
||||
{
|
||||
if (!names.Contains(alias.Name))
|
||||
{
|
||||
await AliasService.DeleteAliasAsync(alias.AliasId);
|
||||
}
|
||||
}
|
||||
foreach (string name in names)
|
||||
{
|
||||
if (!aliases.Exists(item => item.Name == name))
|
||||
{
|
||||
Alias alias = new Alias();
|
||||
alias.Name = name;
|
||||
alias.TenantId = site.TenantId;
|
||||
alias.SiteId = site.SiteId;
|
||||
await AliasService.AddAliasAsync(alias);
|
||||
}
|
||||
}
|
||||
|
||||
await Log(Alias, LogLevel.Information, "Edit", null, "Site Saved {Site}", site);
|
||||
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Log(Alias, LogLevel.Error, "", ex, "Error Saving Site {SiteId} {Error}", Alias.SiteId, ex.Message);
|
||||
AddModuleMessage("Error Saving Site", MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,8 +19,8 @@ else
|
|||
<th>Name</th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><NavLink class="btn btn-primary" href="@(scheme + context.Name + "/admin/site")">Edit</NavLink></td>
|
||||
<td><NavLink class="btn btn-danger" href="@(scheme + context.Name + "/admin/site")">Delete</NavLink></td>
|
||||
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.AliasId.ToString())" /></td>
|
||||
<td><ActionDialog Header="Delete Site" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Site?")" Action="Delete" Security="SecurityAccessLevel.Admin" Class="btn btn-danger" OnClick="@(async () => await DeleteSite(context))" /></td>
|
||||
<td><a href="@(scheme + context.Name)">@context.Name</a></td>
|
||||
</Row>
|
||||
</Pager>
|
||||
|
@ -47,4 +47,31 @@ else
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteSite(Alias Alias)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Alias.SiteId != PageState.Site.SiteId || Alias.TenantId != PageState.Site.TenantId)
|
||||
{
|
||||
await SiteService.DeleteSiteAsync(Alias.SiteId, Alias);
|
||||
await Log(Alias, LogLevel.Information, "", null, "Site Deleted {SiteId}", Alias.SiteId);
|
||||
List<Alias> aliases = await AliasService.GetAliasesAsync();
|
||||
foreach (Alias alias in aliases.Where(item => item.SiteId == Alias.SiteId && item.TenantId == Alias.TenantId).ToList())
|
||||
{
|
||||
await AliasService.DeleteAliasAsync(alias.AliasId);
|
||||
}
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModuleMessage("You Can Not Delete The Current Site", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Log(Alias, LogLevel.Error, "", ex, "Error Deleting Site {SiteId} {Error}", Alias.SiteId, ex.Message);
|
||||
AddModuleMessage("Error Deleting Site", MessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,10 +18,13 @@
|
|||
string classname = "alert alert-danger";
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Message))
|
||||
{
|
||||
message = Message;
|
||||
classname = GetMessageType(Type);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetModuleMessage(string message, MessageType type)
|
||||
{
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace Oqtane.Modules
|
|||
}
|
||||
|
||||
// logging methods
|
||||
public async Task Log(LogLevel level, Exception exception, string message, params object[] args)
|
||||
public async Task Log(Alias alias, LogLevel level, string function, Exception exception, string message, params object[] args)
|
||||
{
|
||||
int PageId = PageState.Page.PageId;
|
||||
int ModuleId = ModuleState.ModuleId;
|
||||
|
@ -141,27 +141,31 @@ namespace Oqtane.Modules
|
|||
}
|
||||
string category = this.GetType().AssemblyQualifiedName;
|
||||
string feature = Utilities.GetTypeNameLastSegment(category, 1);
|
||||
LogFunction function;
|
||||
switch (PageState.Action)
|
||||
LogFunction logfunction;
|
||||
if (string.IsNullOrEmpty(function))
|
||||
{
|
||||
case "Add":
|
||||
function = LogFunction.Create;
|
||||
function = PageState.Action;
|
||||
}
|
||||
switch (function.ToLower())
|
||||
{
|
||||
case "add":
|
||||
logfunction = LogFunction.Create;
|
||||
break;
|
||||
case "Edit":
|
||||
function = LogFunction.Update;
|
||||
case "edit":
|
||||
logfunction = LogFunction.Update;
|
||||
break;
|
||||
case "Delete":
|
||||
function = LogFunction.Delete;
|
||||
case "delete":
|
||||
logfunction = LogFunction.Delete;
|
||||
break;
|
||||
default:
|
||||
function = LogFunction.Read;
|
||||
logfunction = LogFunction.Read;
|
||||
break;
|
||||
}
|
||||
if (feature == "Login")
|
||||
{
|
||||
function = LogFunction.Security;
|
||||
logfunction = LogFunction.Security;
|
||||
}
|
||||
await LoggingService.Log(PageId, ModuleId, UserId, category, feature, function, level, exception, message, args);
|
||||
await LoggingService.Log(alias, PageId, ModuleId, UserId, category, feature, logfunction, level, exception, message, args);
|
||||
}
|
||||
|
||||
public class Logger
|
||||
|
@ -175,62 +179,62 @@ namespace Oqtane.Modules
|
|||
|
||||
public async Task LogTrace(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Trace, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Trace, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogTrace(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Trace, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Trace, "", exception, message, args);
|
||||
}
|
||||
|
||||
public async Task LogDebug(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Debug, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Debug, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogDebug(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Debug, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Debug, "", exception, message, args);
|
||||
}
|
||||
|
||||
public async Task LogInformation(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Information, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Information, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogInformation(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Information, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Information, "", exception, message, args);
|
||||
}
|
||||
|
||||
public async Task LogWarning(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Warning, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Warning, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogWarning(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Warning, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Warning, "", exception, message, args);
|
||||
}
|
||||
|
||||
public async Task LogError(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Error, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Error, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogError(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Error, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Error, "", exception, message, args);
|
||||
}
|
||||
|
||||
public async Task LogCritical(string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Critical, null, message, args);
|
||||
await modulebase.Log(null, LogLevel.Critical, "", null, message, args);
|
||||
}
|
||||
|
||||
public async Task LogCritical(Exception exception, string message, params object[] args)
|
||||
{
|
||||
await modulebase.Log(LogLevel.Critical, exception, message, args);
|
||||
await modulebase.Log(null, LogLevel.Critical, "", exception, message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,6 @@ namespace Oqtane.Services
|
|||
Task<List<Log>> GetLogsAsync(int SiteId, string Level, string Function, int Rows);
|
||||
Task<Log> GetLogAsync(int LogId);
|
||||
Task Log(int? PageId, int? ModuleId, int? UserId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args);
|
||||
Task Log(Alias Alias, int? PageId, int? ModuleId, int? UserId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,14 @@ namespace Oqtane.Services
|
|||
{
|
||||
public interface ISiteService
|
||||
{
|
||||
Task<List<Site>> GetSitesAsync();
|
||||
Task<List<Site>> GetSitesAsync(Alias Alias);
|
||||
|
||||
Task<Site> GetSiteAsync(int SiteId);
|
||||
Task<Site> GetSiteAsync(int SiteId, Alias Alias);
|
||||
|
||||
Task<Site> AddSiteAsync(Site Site, Alias Alias);
|
||||
|
||||
Task<Site> UpdateSiteAsync(Site Site);
|
||||
Task<Site> UpdateSiteAsync(Site Site, Alias Alias);
|
||||
|
||||
Task DeleteSiteAsync(int SiteId);
|
||||
Task DeleteSiteAsync(int SiteId, Alias Alias);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -38,9 +39,21 @@ namespace Oqtane.Services
|
|||
}
|
||||
|
||||
public async Task Log(int? PageId, int? ModuleId, int? UserId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
|
||||
{
|
||||
await Log(null, PageId, ModuleId, UserId, category, feature, function, level, exception, message, args);
|
||||
}
|
||||
|
||||
public async Task Log(Alias Alias, int? PageId, int? ModuleId, int? UserId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)
|
||||
{
|
||||
Log log = new Log();
|
||||
if (Alias == null)
|
||||
{
|
||||
log.SiteId = sitestate.Alias.SiteId;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.SiteId = Alias.SiteId;
|
||||
}
|
||||
log.PageId = PageId;
|
||||
log.ModuleId = ModuleId;
|
||||
log.UserId = UserId;
|
||||
|
@ -56,7 +69,14 @@ namespace Oqtane.Services
|
|||
log.Message = message;
|
||||
log.MessageTemplate = "";
|
||||
log.Properties = JsonSerializer.Serialize(args);
|
||||
if (Alias == null)
|
||||
{
|
||||
await http.PostJsonAsync(apiurl, log);
|
||||
}
|
||||
else
|
||||
{
|
||||
await http.PostJsonAsync(apiurl + "?alias=" + WebUtility.UrlEncode(Alias.Name), log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,12 +123,15 @@ namespace Oqtane.Services
|
|||
setting = await AddSettingAsync(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (setting.SettingValue != kvp.Value)
|
||||
{
|
||||
setting.SettingValue = kvp.Value;
|
||||
setting = await UpdateSettingAsync(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<Setting> GetSettingAsync(int SettingId)
|
||||
|
|
|
@ -27,37 +27,40 @@ namespace Oqtane.Services
|
|||
get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Site"); }
|
||||
}
|
||||
|
||||
public async Task<List<Site>> GetSitesAsync()
|
||||
private string urlsuffix(Alias Alias)
|
||||
{
|
||||
List<Site> sites = await http.GetJsonAsync<List<Site>>(apiurl);
|
||||
string querystring = "";
|
||||
if (Alias != null)
|
||||
{
|
||||
querystring = "?alias=" + WebUtility.UrlEncode(Alias.Name);
|
||||
}
|
||||
return querystring;
|
||||
}
|
||||
|
||||
public async Task<List<Site>> GetSitesAsync(Alias Alias)
|
||||
{
|
||||
List<Site> sites = await http.GetJsonAsync<List<Site>>(apiurl + urlsuffix(Alias));
|
||||
return sites.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<Site> GetSiteAsync(int SiteId)
|
||||
public async Task<Site> GetSiteAsync(int SiteId, Alias Alias)
|
||||
{
|
||||
return await http.GetJsonAsync<Site>(apiurl + "/" + SiteId.ToString());
|
||||
return await http.GetJsonAsync<Site>(apiurl + "/" + SiteId.ToString() + urlsuffix(Alias));
|
||||
}
|
||||
|
||||
public async Task<Site> AddSiteAsync(Site Site, Alias Alias)
|
||||
{
|
||||
if (Alias == null)
|
||||
{
|
||||
return await http.PostJsonAsync<Site>(apiurl, Site);
|
||||
}
|
||||
else
|
||||
{
|
||||
return await http.PostJsonAsync<Site>(apiurl + "?alias=" + WebUtility.UrlEncode(Alias.Name), Site);
|
||||
}
|
||||
return await http.PostJsonAsync<Site>(apiurl + urlsuffix(Alias), Site);
|
||||
}
|
||||
|
||||
public async Task<Site> UpdateSiteAsync(Site Site)
|
||||
public async Task<Site> UpdateSiteAsync(Site Site, Alias Alias)
|
||||
{
|
||||
return await http.PutJsonAsync<Site>(apiurl + "/" + Site.SiteId.ToString(), Site);
|
||||
return await http.PutJsonAsync<Site>(apiurl + "/" + Site.SiteId.ToString() + urlsuffix(Alias), Site);
|
||||
}
|
||||
|
||||
public async Task DeleteSiteAsync(int SiteId)
|
||||
public async Task DeleteSiteAsync(int SiteId, Alias Alias)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + SiteId.ToString());
|
||||
await http.DeleteAsync(apiurl + "/" + SiteId.ToString() + urlsuffix(Alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
}
|
||||
if (PageState == null || reload <= Reload.Site)
|
||||
{
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId);
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId, alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -86,17 +86,9 @@ namespace Oqtane.Controllers
|
|||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
Site Site = Sites.GetSite(id);
|
||||
if (Sites.GetSites().Count() > 1)
|
||||
{
|
||||
Sites.DeleteSite(id);
|
||||
logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log(Site.SiteId, LogLevel.Warning, this, LogFunction.Delete, "Unable to delete the root site.");
|
||||
}
|
||||
logger.Log(id, LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,14 +151,11 @@ namespace Oqtane.Repository
|
|||
}
|
||||
|
||||
public void DeleteSite(int siteId)
|
||||
{
|
||||
if (db.Site.Count() > 1)
|
||||
{
|
||||
var site = db.Site.Find(siteId);
|
||||
db.Site.Remove(site);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSite(Site site)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user