25 lines
940 B
C#
25 lines
940 B
C#
|
|
using System.Web.Mvc;
|
|||
|
|
using AutoMapper;
|
|||
|
|
using Umbraco.Core.Models;
|
|||
|
|
using Umbraco.Web.Trees;
|
|||
|
|
|
|||
|
|
namespace Umbraco.Web.Models.Mapping
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Gets the tree node url for the content or media
|
|||
|
|
/// </summary>
|
|||
|
|
internal class ContentTreeNodeUrlResolver<TSource, TController> : IValueResolver<TSource, object, string>
|
|||
|
|
where TSource : IContentBase
|
|||
|
|
where TController : ContentTreeControllerBase
|
|||
|
|
{
|
|||
|
|
public string Resolve(TSource source, object destination, string destMember, ResolutionContext context)
|
|||
|
|
{
|
|||
|
|
var umbracoContext = context.GetUmbracoContext(throwIfMissing: false);
|
|||
|
|
if (umbracoContext == null) return null;
|
|||
|
|
|
|||
|
|
var urlHelper = new UrlHelper(umbracoContext.HttpContext.Request.RequestContext);
|
|||
|
|
return urlHelper.GetUmbracoApiService<TController>(controller => controller.GetTreeNode(source.Key.ToString("N"), null));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|