2013-07-25 16:08:18 +10:00
|
|
|
|
using System;
|
2013-08-12 14:16:45 +10:00
|
|
|
|
using System.Linq;
|
2013-07-25 16:08:18 +10:00
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
using AutoMapper;
|
2013-05-27 01:23:49 -10:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2013-07-25 16:08:18 +10:00
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
2013-08-12 14:16:45 +10:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2013-05-27 01:23:49 -10:00
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
2013-08-12 14:16:45 +10:00
|
|
|
|
using umbraco;
|
2013-05-27 01:23:49 -10:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
|
|
|
|
{
|
2013-08-12 14:16:45 +10:00
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Declares how model mappings for content
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class ContentModelMapper : MapperConfiguration
|
2013-05-27 01:23:49 -10:00
|
|
|
|
{
|
2013-07-25 16:08:18 +10:00
|
|
|
|
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
|
2013-06-03 23:50:20 -10:00
|
|
|
|
{
|
2013-08-12 14:16:45 +10:00
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
//FROM IContent TO ContentItemDisplay
|
|
|
|
|
|
config.CreateMap<IContent, ContentItemDisplay>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IContent>>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Updator,
|
|
|
|
|
|
expression => expression.ResolveUsing<CreatorResolver>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Icon,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Icon))
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeAlias,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Alias))
|
2013-08-12 14:16:45 +10:00
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeName,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Name))
|
2013-07-25 16:08:18 +10:00
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.PublishDate,
|
|
|
|
|
|
expression => expression.MapFrom(content => GetPublishedDate(content, applicationContext)))
|
2013-08-12 14:16:45 +10:00
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Template,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.Template.Name))
|
2013-07-25 16:08:18 +10:00
|
|
|
|
.ForMember(display => display.Properties, expression => expression.Ignore())
|
2013-08-12 14:16:45 +10:00
|
|
|
|
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>())
|
|
|
|
|
|
.AfterMap((content, display) => TabsAndPropertiesResolver.MapGenericProperties(content, display, new ContentPropertyDisplay
|
|
|
|
|
|
{
|
|
|
|
|
|
Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
|
|
|
|
|
|
Label = "Template", //TODO: localize this?
|
|
|
|
|
|
Value = display.Template,
|
|
|
|
|
|
View = "templatepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
|
|
|
|
|
|
}));
|
2013-05-27 01:23:49 -10:00
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
//FROM IContent TO ContentItemBasic<ContentPropertyBasic, IContent>
|
|
|
|
|
|
config.CreateMap<IContent, ContentItemBasic<ContentPropertyBasic, IContent>>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IContent>>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Updator,
|
|
|
|
|
|
expression => expression.ResolveUsing<CreatorResolver>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Icon,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Icon))
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeAlias,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Alias));
|
2013-06-10 16:43:42 -02:00
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
//FROM IContent TO ContentItemDto<IContent>
|
|
|
|
|
|
config.CreateMap<IContent, ContentItemDto<IContent>>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IContent>>());
|
2013-06-10 16:43:42 -02:00
|
|
|
|
|
|
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
}
|
2013-06-10 16:43:42 -02:00
|
|
|
|
|
2013-07-25 16:08:18 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the published date value for the IContent object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="content"></param>
|
|
|
|
|
|
/// <param name="applicationContext"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static DateTime? GetPublishedDate(IContent content, ApplicationContext applicationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (content.Published)
|
|
|
|
|
|
{
|
|
|
|
|
|
return content.UpdateDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (content.HasPublishedVersion())
|
|
|
|
|
|
{
|
|
|
|
|
|
var published = applicationContext.Services.ContentService.GetPublishedVersion(content.Id);
|
|
|
|
|
|
return published.UpdateDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2013-06-10 16:43:42 -02:00
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-25 16:08:18 +10:00
|
|
|
|
}
|