Files
Umbraco-CMS/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs
2021-08-17 13:09:25 +02:00

44 lines
1.6 KiB
C#

using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Website.Models;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.Website.Controllers
{
public class RenderNoContentController : Controller
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IIOHelper _ioHelper;
private readonly IOptions<GlobalSettings> _globalSettings;
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptions<GlobalSettings> globalSettings)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
}
public ActionResult Index()
{
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
var store = umbracoContext.Content;
if (store.HasContent())
{
// If there is actually content, go to the root.
return Redirect("~/");
}
var model = new NoNodesViewModel
{
UmbracoPath = _ioHelper.ResolveUrl(_globalSettings.Value.UmbracoPath),
};
return View(_globalSettings.Value.NoNodesViewPath, model);
}
}
}