Fixes: U4-7691 - refactor

This commit is contained in:
Claus
2016-02-03 15:39:18 +01:00
parent 864ca4e40e
commit 6a1e54b221
2 changed files with 29 additions and 7 deletions

View File

@@ -75,7 +75,7 @@ namespace Umbraco.Web.Models.Mapping
.ConstructUsing((source) => new MediaType(source.ParentId))
.AfterMap((source, dest) =>
{
ContentTypeModelMapperExtensions.AfterMapContentTypeSaveToEntity(source, dest, applicationContext);
ContentTypeModelMapperExtensions.AfterMapMediaTypeSaveToEntity(source, dest, applicationContext);
});
config.CreateMap<MemberTypeSave, IMemberType>()

View File

@@ -69,12 +69,34 @@ namespace Umbraco.Web.Models.Mapping
foreach (var a in add)
{
//TODO: Remove N+1 lookup
//since we don't really know from the alias what type of content type this is,
//we look up by content type first and then by media type if not found.
//content type aliases are unique so this should be safe to do.
IContentTypeComposition addCt = applicationContext.Services.ContentTypeService.GetContentType(a);
if (addCt == null)
addCt = applicationContext.Services.ContentTypeService.GetMediaType(a);
var addCt = applicationContext.Services.ContentTypeService.GetContentType(a);
if (addCt != null)
dest.AddContentType(addCt);
}
}
public static void AfterMapMediaTypeSaveToEntity<TSource, TDestination>(
TSource source, TDestination dest,
ApplicationContext applicationContext)
where TSource : MediaTypeSave
where TDestination : IContentTypeComposition
{
//sync compositions
var current = dest.CompositionAliases().ToArray();
var proposed = source.CompositeContentTypes;
var remove = current.Where(x => proposed.Contains(x) == false);
var add = proposed.Where(x => current.Contains(x) == false);
foreach (var rem in remove)
{
dest.RemoveContentType(rem);
}
foreach (var a in add)
{
//TODO: Remove N+1 lookup
var addCt = applicationContext.Services.ContentTypeService.GetMediaType(a);
if (addCt != null)
dest.AddContentType(addCt);
}