Unable to deleted the root site

This commit is contained in:
Hisham Bin Ateya
2020-02-15 09:07:29 +03:00
parent ae24b0f3be
commit ece378c54f
2 changed files with 16 additions and 6 deletions

View File

@ -86,9 +86,16 @@ namespace Oqtane.Controllers
[HttpDelete("{id}")] [HttpDelete("{id}")]
[Authorize(Roles = Constants.HostRole)] [Authorize(Roles = Constants.HostRole)]
public void Delete(int id) public void Delete(int id)
{
if (Sites.GetSites().Count() > 1)
{ {
Sites.DeleteSite(id); Sites.DeleteSite(id);
logger.Log(LogLevel.Information, this, LogFunction.Delete, "Site Deleted {SiteId}", 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) 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.Site.Remove(site);
db.SaveChanges(); db.SaveChanges();
} }
}
private void CreateSite(Site site) private void CreateSite(Site site)
{ {