2021-08-11 13:25:17 +02:00
|
|
|
using System;
|
2020-11-03 18:55:55 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.IO;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
|
|
|
|
using Umbraco.Cms.Web.Website.Models;
|
2021-08-17 13:09:25 +02:00
|
|
|
using Umbraco.Extensions;
|
2020-02-29 14:26:35 +01:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Web.Website.Controllers
|
2020-02-29 14:26:35 +01:00
|
|
|
{
|
|
|
|
|
public class RenderNoContentController : Controller
|
|
|
|
|
{
|
2020-04-14 16:26:01 +02:00
|
|
|
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
2020-02-29 14:26:35 +01:00
|
|
|
private readonly IIOHelper _ioHelper;
|
2020-11-03 18:55:55 +01:00
|
|
|
private readonly IOptions<GlobalSettings> _globalSettings;
|
2020-02-29 14:26:35 +01:00
|
|
|
|
2020-11-03 18:55:55 +01:00
|
|
|
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptions<GlobalSettings> globalSettings)
|
2020-02-29 14:26:35 +01:00
|
|
|
{
|
2020-04-14 16:26:01 +02:00
|
|
|
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
2020-02-29 14:26:35 +01:00
|
|
|
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
2020-08-23 13:55:36 +02:00
|
|
|
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
|
2020-02-29 14:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2021-08-17 13:09:25 +02:00
|
|
|
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
|
2021-08-11 13:25:17 +02:00
|
|
|
var store = umbracoContext.Content;
|
2020-02-29 14:26:35 +01:00
|
|
|
if (store.HasContent())
|
|
|
|
|
{
|
|
|
|
|
// If there is actually content, go to the root.
|
|
|
|
|
return Redirect("~/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var model = new NoNodesViewModel
|
|
|
|
|
{
|
2020-11-03 18:55:55 +01:00
|
|
|
UmbracoPath = _ioHelper.ResolveUrl(_globalSettings.Value.UmbracoPath),
|
2020-02-29 14:26:35 +01:00
|
|
|
};
|
|
|
|
|
|
2020-11-03 18:55:55 +01:00
|
|
|
return View(_globalSettings.Value.NoNodesViewPath, model);
|
2020-02-29 14:26:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|