mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
DefaultContentManager now takes a dependency on IContentDefinitionManager ContentItem.TypeDefinition assigned to ContentTypeDefinition instance when creating ContentPart.TypePartDefinition assigned to ContentTypeDefinition.Part instance as added Empty definition instances are created as code-only types and parts are created --HG-- branch : dev
51 lines
2.1 KiB
C#
51 lines
2.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using Orchard.ContentManagement;
|
|
using Orchard.ContentManagement.Aspects;
|
|
using Orchard.Core.Common.Models;
|
|
using Orchard.Core.Routable.Models;
|
|
using Orchard.Core.Routable.ViewModels;
|
|
using Orchard.Mvc.ViewModels;
|
|
|
|
namespace Orchard.Core.Routable.Controllers {
|
|
[ValidateInput(false)]
|
|
public class ItemController : Controller {
|
|
private readonly IContentManager _contentManager;
|
|
private readonly IRoutablePathConstraint _routablePathConstraint;
|
|
|
|
public ItemController(IContentManager contentManager, IRoutablePathConstraint routablePathConstraint) {
|
|
_contentManager = contentManager;
|
|
_routablePathConstraint = routablePathConstraint;
|
|
}
|
|
|
|
public ActionResult Display(string path) {
|
|
var matchedPath = _routablePathConstraint.FindPath(path);
|
|
if (string.IsNullOrEmpty(matchedPath)) {
|
|
throw new ApplicationException("404 - should not have passed path constraint");
|
|
}
|
|
|
|
var hits = _contentManager
|
|
.Query<IsRoutable, RoutableRecord>(VersionOptions.Published)
|
|
.Where(r => r.Path == matchedPath)
|
|
.Slice(0, 2);
|
|
if (hits.Count() == 0) {
|
|
throw new ApplicationException("404 - should not have passed path constraint");
|
|
}
|
|
if (hits.Count() != 1) {
|
|
throw new ApplicationException("Ambiguous content");
|
|
}
|
|
var model = new RoutableDisplayViewModel {
|
|
Routable = _contentManager.BuildDisplayModel<IRoutableAspect>(hits.Single(), "Detail")
|
|
};
|
|
PrepareDisplayViewModel(model.Routable);
|
|
return View("Display", model);
|
|
}
|
|
|
|
private void PrepareDisplayViewModel(ContentItemViewModel<IRoutableAspect> itemViewModel) {
|
|
if (string.IsNullOrEmpty(itemViewModel.TemplateName)) {
|
|
itemViewModel.TemplateName = "Items/Contents.Item";
|
|
}
|
|
}
|
|
}
|
|
} |