2013-11-07 17:16:22 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Declares model mappings for media.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class MediaModelMapper : MapperConfiguration
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
//FROM IMedia TO MediaItemDisplay
|
|
|
|
|
|
config.CreateMap<IMedia, MediaItemDisplay>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IMedia>>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Icon,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Icon))
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeAlias,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Alias))
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeName,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Name))
|
|
|
|
|
|
.ForMember(display => display.Properties, expression => expression.Ignore())
|
|
|
|
|
|
.ForMember(display => display.Tabs, expression => expression.ResolveUsing<TabsAndPropertiesResolver>())
|
|
|
|
|
|
.AfterMap(MapGenericCustomProperties);
|
|
|
|
|
|
/*
|
|
|
|
|
|
.AfterMap((media, display) => TabsAndPropertiesResolver.MapGenericProperties(media, display));
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//FROM IMedia TO ContentItemBasic<ContentPropertyBasic, IMedia>
|
|
|
|
|
|
config.CreateMap<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IMedia>>())
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Icon,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Icon))
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.ContentTypeAlias,
|
|
|
|
|
|
expression => expression.MapFrom(content => content.ContentType.Alias));
|
|
|
|
|
|
|
|
|
|
|
|
//FROM IMedia TO ContentItemDto<IMedia>
|
|
|
|
|
|
config.CreateMap<IMedia, ContentItemDto<IMedia>>()
|
|
|
|
|
|
.ForMember(
|
|
|
|
|
|
dto => dto.Owner,
|
|
|
|
|
|
expression => expression.ResolveUsing<OwnerResolver<IMedia>>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void MapGenericCustomProperties(IMedia media, MediaItemDisplay display)
|
|
|
|
|
|
{
|
2013-11-15 16:56:51 +11:00
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
if (media.ContentType.IsContainer)
|
|
|
|
|
|
{
|
2013-11-15 16:56:51 +11:00
|
|
|
|
TabsAndPropertiesResolver.AddContainerView(display, "media");
|
|
|
|
|
|
}
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
|
|
TabsAndPropertiesResolver.MapGenericProperties(media, display);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|