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> </Header>
<Row> <Row>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.AliasId.ToString())" /></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.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> <td><a href="@(scheme + context.Name)">@context.Name</a></td>
</Row> </Row>
</Pager> </Pager>

View File

@ -28,7 +28,14 @@
} }
@if (authorized) @if (authorized)
{ {
<button class="@Class" @onclick="DisplayModal">@Text</button> if (Disabled)
{
<button class="@Class" disabled @onclick="DisplayModal">@Text</button>
}
else
{
<button class="@Class" @onclick="DisplayModal">@Text</button>
}
} }
@code { @code {
@ -36,13 +43,13 @@
public string Header { get; set; } // required public string Header { get; set; } // required
[Parameter] [Parameter]
public string Message { get; set; } // required public string Message { get; set; } // required
[Parameter] [Parameter]
public string Text { get; set; } // optional - defaults to Action if not specified public string Text { get; set; } // optional - defaults to Action if not specified
[Parameter] [Parameter]
public string Action { get; set; } // optional public string Action { get; set; } // optional
[Parameter] [Parameter]
public SecurityAccessLevel? Security { get; set; } // optional - can be used to explicitly specify SecurityAccessLevel public SecurityAccessLevel? Security { get; set; } // optional - can be used to explicitly specify SecurityAccessLevel
@ -50,6 +57,9 @@
[Parameter] [Parameter]
public string Class { get; set; } // optional public string Class { get; set; } // optional
[Parameter]
public bool Disabled { get; set; } // optional
[Parameter] [Parameter]
public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true public string EditMode { get; set; } // optional - specifies if a user must be in edit mode to see the action - default is true

View File

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

View File

@ -87,8 +87,15 @@ namespace Oqtane.Controllers
[Authorize(Roles = Constants.HostRole)] [Authorize(Roles = Constants.HostRole)]
public void Delete(int id) public void Delete(int id)
{ {
Sites.DeleteSite(id); if (Sites.GetSites().Count() > 1)
logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", id); {
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

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