Merge pull request #209 from hishamco/root-site

Unable to deleted the root site
This commit is contained in:
Shaun Walker 2020-02-22 10:03:23 -05:00 committed by GitHub
commit 07b29bff1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 11 deletions

View File

@ -20,7 +20,7 @@ else
</Header>
<Row>
<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.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite(context))" /></td>
<td><ActionDialog Header="Delete Site" Message="@("Are You Sure You Wish To Delete The " + context.Name + " Site?")" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite(context))" Disabled="sites.Count == 1" /></td>
<td><a href="@(scheme + context.Name)">@context.Name</a></td>
</Row>
</Pager>

View File

@ -27,9 +27,16 @@
</div>
}
@if (authorized)
{
if (Disabled)
{
<button class="@Class" disabled @onclick="DisplayModal">@Text</button>
}
else
{
<button class="@Class" @onclick="DisplayModal">@Text</button>
}
}
@code {
[Parameter]
@ -50,6 +57,9 @@
[Parameter]
public string Class { get; set; } // optional
[Parameter]
public bool Disabled { get; set; } // optional
[Parameter]
public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true

View File

@ -3,9 +3,16 @@
@inject IUserService UserService
@if (authorized)
{
if (Disabled)
{
<NavLink class="@classname" href="@url" style="@style" disabled>@text</NavLink>
}
else
{
<NavLink class="@classname" href="@url" style="@style">@text</NavLink>
}
}
@code {
[Parameter]
@ -26,6 +33,9 @@
[Parameter]
public string Style { get; set; } // optional
[Parameter]
public bool Disabled { get; set; } // optional
[Parameter]
public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true

View File

@ -86,9 +86,16 @@ namespace Oqtane.Controllers
[HttpDelete("{id}")]
[Authorize(Roles = Constants.HostRole)]
public void Delete(int id)
{
if (Sites.GetSites().Count() > 1)
{
Sites.DeleteSite(id);
logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id);
}
else
{
logger.Log(LogLevel.Warning, this, LogFunction.Delete, "Unable to delete the root site.");
}
}
}
}

View File

@ -143,10 +143,13 @@ namespace Oqtane.Repository
public void DeleteSite(int siteId)
{
Site site = db.Site.Find(siteId);
if (db.Site.Count() > 1)
{
var site = db.Site.Find(siteId);
db.Site.Remove(site);
db.SaveChanges();
}
}
private void CreateSite(Site site)
{