Merge pull request #5192 from umbraco/v8/bugfix/5183-mapping-enumerables

Fix mapping of enumerable
This commit is contained in:
Bjarke Berg
2019-04-09 11:51:39 +02:00
committed by GitHub
28 changed files with 154 additions and 64 deletions
+13
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Core.Mapping
{
@@ -112,6 +113,18 @@ namespace Umbraco.Core.Mapping
}
*/
/// <summary>
/// Maps an enumerable of source objects to a new list of target objects.
/// </summary>
/// <typeparam name="TSourceElement">The type of the source objects.</typeparam>
/// <typeparam name="TTargetElement">The type of the target objects.</typeparam>
/// <param name="source">The source objects.</param>
/// <returns>A list containing the target objects.</returns>
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source)
{
return source.Select(Map<TSourceElement, TTargetElement>).ToList();
}
#endregion
}
}
+42 -2
View File
@@ -229,7 +229,7 @@ namespace Umbraco.Core.Mapping
if (ctor != null && map != null)
{
// register (for next time) and do it now (for this time)
object NCtor(object s, MapperContext c) => MapEnumerable<TTarget>((IEnumerable) s, targetGenericArg, ctor, map, c);
object NCtor(object s, MapperContext c) => MapEnumerableInternal<TTarget>((IEnumerable) s, targetGenericArg, ctor, map, c);
DefineCtors(sourceType)[targetType] = NCtor;
DefineMaps(sourceType)[targetType] = Identity;
return (TTarget) NCtor(source, context);
@@ -241,7 +241,7 @@ namespace Umbraco.Core.Mapping
throw new InvalidOperationException($"Don't know how to map {sourceType.FullName} to {targetType.FullName}.");
}
private TTarget MapEnumerable<TTarget>(IEnumerable source, Type targetGenericArg, Func<object, MapperContext, object> ctor, Action<object, object, MapperContext> map, MapperContext context)
private TTarget MapEnumerableInternal<TTarget>(IEnumerable source, Type targetGenericArg, Func<object, MapperContext, object> ctor, Action<object, object, MapperContext> map, MapperContext context)
{
var targetList = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(targetGenericArg));
@@ -379,6 +379,46 @@ namespace Umbraco.Core.Mapping
throw new Exception("panic");
}
/// <summary>
/// Maps an enumerable of source objects to a new list of target objects.
/// </summary>
/// <typeparam name="TSourceElement">The type of the source objects.</typeparam>
/// <typeparam name="TTargetElement">The type of the target objects.</typeparam>
/// <param name="source">The source objects.</param>
/// <returns>A list containing the target objects.</returns>
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source)
{
return source.Select(Map<TSourceElement, TTargetElement>).ToList();
}
/// <summary>
/// Maps an enumerable of source objects to a new list of target objects.
/// </summary>
/// <typeparam name="TSourceElement">The type of the source objects.</typeparam>
/// <typeparam name="TTargetElement">The type of the target objects.</typeparam>
/// <param name="source">The source objects.</param>
/// <param name="f">A mapper context preparation method.</param>
/// <returns>A list containing the target objects.</returns>
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source, Action<MapperContext> f)
{
var context = new MapperContext(this);
f(context);
return source.Select(x => Map<TSourceElement, TTargetElement>(x, context)).ToList();
}
/// <summary>
/// Maps an enumerable of source objects to a new list of target objects.
/// </summary>
/// <typeparam name="TSourceElement">The type of the source objects.</typeparam>
/// <typeparam name="TTargetElement">The type of the target objects.</typeparam>
/// <param name="source">The source objects.</param>
/// <param name="context">A mapper context.</param>
/// <returns>A list containing the target objects.</returns>
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source, MapperContext context)
{
return source.Select(x => Map<TSourceElement, TTargetElement>(x, context)).ToList();
}
#endregion
}
}
+44 -10
View File
@@ -2,6 +2,8 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Tests.Mapping
{
@@ -11,11 +13,11 @@ namespace Umbraco.Tests.Mapping
[Test]
public void SimpleMap()
{
var profiles = new MapDefinitionCollection(new IMapDefinition[]
var definitions = new MapDefinitionCollection(new IMapDefinition[]
{
new Profile1(),
new MapperDefinition1(),
});
var mapper = new UmbracoMapper(profiles);
var mapper = new UmbracoMapper(definitions);
var thing1 = new Thing1 { Value = "value" };
var thing2 = mapper.Map<Thing1, Thing2>(thing1);
@@ -36,11 +38,11 @@ namespace Umbraco.Tests.Mapping
[Test]
public void EnumerableMap()
{
var profiles = new MapDefinitionCollection(new IMapDefinition[]
var definitions = new MapDefinitionCollection(new IMapDefinition[]
{
new Profile1(),
new MapperDefinition1(),
});
var mapper = new UmbracoMapper(profiles);
var mapper = new UmbracoMapper(definitions);
var thing1A = new Thing1 { Value = "valueA" };
var thing1B = new Thing1 { Value = "valueB" };
@@ -58,16 +60,23 @@ namespace Umbraco.Tests.Mapping
Assert.AreEqual(2, thing2.Count);
Assert.AreEqual("valueA", thing2[0].Value);
Assert.AreEqual("valueB", thing2[1].Value);
thing2 = mapper.MapEnumerable<Thing1, Thing2>(thing1).ToList();
Assert.IsNotNull(thing2);
Assert.AreEqual(2, thing2.Count);
Assert.AreEqual("valueA", thing2[0].Value);
Assert.AreEqual("valueB", thing2[1].Value);
}
[Test]
public void InheritedMap()
{
var profiles = new MapDefinitionCollection(new IMapDefinition[]
var definitions = new MapDefinitionCollection(new IMapDefinition[]
{
new Profile1(),
new MapperDefinition1(),
});
var mapper = new UmbracoMapper(profiles);
var mapper = new UmbracoMapper(definitions);
var thing3 = new Thing3 { Value = "value" };
var thing2 = mapper.Map<Thing3, Thing2>(thing3);
@@ -85,6 +94,20 @@ namespace Umbraco.Tests.Mapping
Assert.AreEqual("value", thing2.Value);
}
[Test]
public void CollectionsMap()
{
var definitions = new MapDefinitionCollection(new IMapDefinition[]
{
new MapperDefinition2(),
});
var mapper = new UmbracoMapper(definitions);
// can map a PropertyCollection
var source = new PropertyCollection();
var target = mapper.Map<IEnumerable<ContentPropertyDto>>(source);
}
private class Thing1
{
public string Value { get; set; }
@@ -98,7 +121,7 @@ namespace Umbraco.Tests.Mapping
public string Value { get; set; }
}
private class Profile1 : IMapDefinition
private class MapperDefinition1 : IMapDefinition
{
public void DefineMaps(UmbracoMapper mapper)
{
@@ -110,5 +133,16 @@ namespace Umbraco.Tests.Mapping
target.Value = source.Value;
}
}
private class MapperDefinition2 : IMapDefinition
{
public void DefineMaps(UmbracoMapper mapper)
{
mapper.Define<Property, ContentPropertyDto>((source, context) => new ContentPropertyDto(), Map);
}
private static void Map(Property source, ContentPropertyDto target, MapperContext context)
{ }
}
}
}
+1 -1
View File
@@ -190,7 +190,7 @@ namespace Umbraco.Web.Editors
//get all user groups and map their default permissions to the AssignedUserGroupPermissions model.
//we do this because not all groups will have true assigned permissions for this node so if they don't have assigned permissions, we need to show the defaults.
var defaultPermissionsByGroup = Mapper.Map<IEnumerable<AssignedUserGroupPermissions>>(allUserGroups).ToArray();
var defaultPermissionsByGroup = Mapper.MapEnumerable<IUserGroup, AssignedUserGroupPermissions>(allUserGroups);
var defaultPermissionsAsDictionary = defaultPermissionsByGroup
.ToDictionary(x => Convert.ToInt32(x.Id), x => x);
+3 -3
View File
@@ -917,7 +917,7 @@ namespace Umbraco.Web.Editors
.SelectMany(x => x.PropertyTypes)
.DistinctBy(composition => composition.Alias);
var filteredPropertyTypes = ExecutePostFilter(propertyTypes, postFilter);
return Mapper.Map<IEnumerable<PropertyType>, IEnumerable<EntityBasic>>(filteredPropertyTypes);
return Mapper.MapEnumerable<PropertyType, EntityBasic>(filteredPropertyTypes);
case UmbracoEntityTypes.PropertyGroup:
@@ -928,13 +928,13 @@ namespace Umbraco.Web.Editors
.SelectMany(x => x.PropertyGroups)
.DistinctBy(composition => composition.Name);
var filteredpropertyGroups = ExecutePostFilter(propertyGroups, postFilter);
return Mapper.Map<IEnumerable<PropertyGroup>, IEnumerable<EntityBasic>>(filteredpropertyGroups);
return Mapper.MapEnumerable<PropertyGroup, EntityBasic>(filteredpropertyGroups);
case UmbracoEntityTypes.User:
var users = Services.UserService.GetAll(0, int.MaxValue, out _);
var filteredUsers = ExecutePostFilter(users, postFilter);
return Mapper.Map<IEnumerable<IUser>, IEnumerable<EntityBasic>>(filteredUsers);
return Mapper.MapEnumerable<IUser, EntityBasic>(filteredUsers);
case UmbracoEntityTypes.Stylesheet:
@@ -46,7 +46,7 @@ namespace Umbraco.Web.Editors
{
var allLanguages = Services.LocalizationService.GetAllLanguages();
return Mapper.Map<IEnumerable<ILanguage>, IEnumerable<Language>>(allLanguages);
return Mapper.MapEnumerable<ILanguage, Language>(allLanguages);
}
[HttpGet]
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Umbraco.Web.Editors
var dateQuery = sinceDate.HasValue ? SqlContext.Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate) : null;
var userId = Security.GetUserId().ResultOr(0);
var result = Services.AuditService.GetPagedItemsByUser(userId, pageNumber - 1, pageSize, out totalRecords, orderDirection, customFilter:dateQuery);
var mapped = Mapper.Map<IEnumerable<AuditLog>>(result);
var mapped = Mapper.MapEnumerable<IAuditItem, AuditLog>(result);
return new PagedResult<AuditLog>(totalRecords, pageNumber, pageSize)
{
Items = MapAvatarsAndNames(mapped)
@@ -49,7 +49,7 @@ namespace Umbraco.Web.Editors
? redirectUrlService.GetAllRedirectUrls(page, pageSize, out resultCount)
: redirectUrlService.SearchRedirectUrls(searchTerm, page, pageSize, out resultCount);
searchResult.SearchResults = Mapper.Map<IEnumerable<ContentRedirectUrl>>(redirects).ToArray();
searchResult.SearchResults = Mapper.MapEnumerable<IRedirectUrl, ContentRedirectUrl>(redirects);
searchResult.TotalCount = resultCount;
searchResult.CurrentPage = page;
searchResult.PageCount = ((int)resultCount + pageSize - 1) / pageSize;
@@ -71,9 +71,10 @@ namespace Umbraco.Web.Editors
{
var redirectUrlService = Services.RedirectUrlService;
var redirects = redirectUrlService.GetContentRedirectUrls(guidIdi.Guid);
redirectsResult.SearchResults = Mapper.Map<IEnumerable<ContentRedirectUrl>>(redirects).ToArray();
var mapped = Mapper.MapEnumerable<IRedirectUrl, ContentRedirectUrl>(redirects);
redirectsResult.SearchResults = mapped;
//not doing paging 'yet'
redirectsResult.TotalCount = redirects.Count();
redirectsResult.TotalCount = mapped.Count();
redirectsResult.CurrentPage = 1;
redirectsResult.PageCount = 1;
}
@@ -34,11 +34,11 @@ namespace Umbraco.Web.Editors
if (string.IsNullOrWhiteSpace(relationTypeAlias) == false)
{
return
Mapper.Map<IEnumerable<IRelation>, IEnumerable<RelationDisplay>>(
Mapper.MapEnumerable<IRelation, RelationDisplay>(
relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias)));
}
return Mapper.Map<IEnumerable<IRelation>, IEnumerable<RelationDisplay>>(relations);
return Mapper.MapEnumerable<IRelation, RelationDisplay>(relations);
}
[HttpDelete]
@@ -48,7 +48,7 @@ namespace Umbraco.Web.Editors
var relations = Services.RelationService.GetByRelationTypeId(relationType.Id);
var display = Mapper.Map<IRelationType, RelationTypeDisplay>(relationType);
display.Relations = Mapper.Map<IEnumerable<IRelation>, IEnumerable<RelationDisplay>>(relations);
display.Relations = Mapper.MapEnumerable<IRelation, RelationDisplay>(relations);
return display;
}
@@ -102,7 +102,7 @@ namespace Umbraco.Web.Editors
/// <returns></returns>
public IEnumerable<UserGroupBasic> GetUserGroups(bool onlyCurrentUserGroups = true)
{
var allGroups = Mapper.Map<IEnumerable<IUserGroup>, IEnumerable<UserGroupBasic>>(Services.UserService.GetAllUserGroups())
var allGroups = Mapper.MapEnumerable<IUserGroup, UserGroupBasic>(Services.UserService.GetAllUserGroups())
.ToList();
var isAdmin = Security.CurrentUser.IsAdmin();
+1 -1
View File
@@ -238,7 +238,7 @@ namespace Umbraco.Web.Editors
var paged = new PagedUserResult(total, pageNumber, pageSize)
{
Items = Mapper.Map<IEnumerable<UserBasic>>(result),
Items = Mapper.MapEnumerable<IUser, UserBasic>(result),
UserStates = Services.UserService.GetUserStates()
};
@@ -64,7 +64,7 @@ namespace Umbraco.Web.Models.Mapping
// Umbraco.Code.MapAll
private static void Map(IContent source, ContentPropertyCollectionDto target, MapperContext context)
{
target.Properties = source.Properties.Select(context.Map<ContentPropertyDto>);
target.Properties = context.MapEnumerable<Property, ContentPropertyDto>(source.Properties);
}
// Umbraco.Code.MapAll -AllowPreview -Errors -PersistedContent
@@ -98,7 +98,7 @@ namespace Umbraco.Web.Models.Mapping
target.Variants = _contentVariantMapper.Map(source, context);
target.ContentDto = new ContentPropertyCollectionDto();
target.ContentDto.Properties = source.Properties.Select(context.Map<ContentPropertyDto>);
target.ContentDto.Properties = context.MapEnumerable<Property, ContentPropertyDto>(source.Properties);
}
// Umbraco.Code.MapAll -Segment -Language
@@ -127,7 +127,7 @@ namespace Umbraco.Web.Models.Mapping
target.Owner = _commonMapper.GetOwner(source, context);
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Properties = source.Properties.Select(context.Map<ContentPropertyBasic>);
target.Properties = context.MapEnumerable<Property, ContentPropertyBasic>(source.Properties);
target.SortOrder = source.SortOrder;
target.State = _basicStateMapper.Map(source, context);
target.Trashed = source.Trashed;
@@ -122,7 +122,7 @@ namespace Umbraco.Web.Models.Mapping
target.AllowCultureVariant = source.VariesByCulture();
//sync templates
target.AllowedTemplates = source.AllowedTemplates.Select(context.Map<EntityBasic>).ToArray();
target.AllowedTemplates = context.MapEnumerable<ITemplate, EntityBasic>(source.AllowedTemplates);
if (source.DefaultTemplate != null)
target.DefaultTemplate = context.Map<EntityBasic>(source.DefaultTemplate);
@@ -312,7 +312,7 @@ namespace Umbraco.Web.Models.Mapping
target.Name = source.Name;
target.SortOrder = source.SortOrder;
target.Properties = source.Properties.Select(context.Map<PropertyTypeDisplay>);
target.Properties = context.MapEnumerable<PropertyTypeBasic, PropertyTypeDisplay>(source.Properties);
}
// Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames
@@ -325,7 +325,7 @@ namespace Umbraco.Web.Models.Mapping
target.Name = source.Name;
target.SortOrder = source.SortOrder;
target.Properties = source.Properties.Select(context.Map<MemberPropertyTypeDisplay>);
target.Properties = context.MapEnumerable<MemberPropertyTypeBasic, MemberPropertyTypeDisplay>(source.Properties);
}
// Umbraco.Code.MapAll -Editor -View -Config -ContentTypeId -ContentTypeName -Locked
@@ -531,7 +531,7 @@ namespace Umbraco.Web.Models.Mapping
{
MapTypeToDisplayBase(source, target);
target.Groups = source.Groups.Select(context.Map<PropertyGroupDisplay<TTargetPropertyType>>);
target.Groups = context.MapEnumerable<PropertyGroupBasic<TSourcePropertyType>, PropertyGroupDisplay<TTargetPropertyType>>(source.Groups);
}
private IEnumerable<string> MapLockedCompositions(IContentTypeComposition source)
@@ -32,7 +32,7 @@ namespace Umbraco.Web.Models.Mapping
var allLanguages = _localizationService.GetAllLanguages().OrderBy(x => x.Id).ToList();
if (allLanguages.Count == 0) return Enumerable.Empty<ContentVariantDisplay>(); //this should never happen
var langs = context.Map<IEnumerable<Language>>(allLanguages).ToList();
var langs = context.MapEnumerable<ILanguage, Language>(allLanguages).ToList();
//create a variant for each language, then we'll populate the values
var variants = langs.Select(x =>
@@ -127,10 +127,10 @@ namespace Umbraco.Web.Models.Mapping
private IEnumerable<PropertyEditorBasic> MapAvailableEditors(IDataType source, MapperContext context)
{
var contentSection = Current.Configs.Settings().Content;
return _propertyEditors
var properties = _propertyEditors
.Where(x => !x.IsDeprecated || contentSection.ShowDeprecatedPropertyEditors || source.EditorAlias == x.Alias)
.OrderBy(x => x.Name)
.Select(context.Map<PropertyEditorBasic>);
.OrderBy(x => x.Name);
return context.MapEnumerable<IDataEditor, PropertyEditorBasic>(properties);
}
private IEnumerable<DataTypeConfigurationFieldDisplay> MapPreValues(IDataType dataType, MapperContext context)
@@ -143,7 +143,7 @@ namespace Umbraco.Web.Models.Mapping
throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\".");
var configurationEditor = editor.GetConfigurationEditor();
var fields = configurationEditor.Fields.Select(context.Map<DataTypeConfigurationFieldDisplay>).ToArray();
var fields = context.MapEnumerable<ConfigurationField,DataTypeConfigurationFieldDisplay>(configurationEditor.Fields);
var configurationDictionary = configurationEditor.ToConfigurationEditor(dataType.Configuration);
MapConfigurationFields(fields, configurationDictionary);
@@ -151,7 +151,7 @@ namespace Umbraco.Web.Models.Mapping
return fields;
}
private void MapConfigurationFields(DataTypeConfigurationFieldDisplay[] fields, IDictionary<string, object> configuration)
private void MapConfigurationFields(List<DataTypeConfigurationFieldDisplay> fields, IDictionary<string, object> configuration)
{
if (fields == null) throw new ArgumentNullException(nameof(fields));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
@@ -190,7 +190,7 @@ namespace Umbraco.Web.Models.Mapping
var configurationEditor = source.GetConfigurationEditor();
var fields = configurationEditor.Fields.Select(context.Map<DataTypeConfigurationFieldDisplay>).ToArray();
var fields = context.MapEnumerable<ConfigurationField, DataTypeConfigurationFieldDisplay>(configurationEditor.Fields);
var defaultConfiguration = configurationEditor.DefaultConfiguration;
if (defaultConfiguration != null)
@@ -26,8 +26,8 @@ namespace Umbraco.Web.Models.Mapping
mapper.Define<IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<EntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
mapper.Define<ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) => source.Select(context.Map<SearchResultEntity>).ToList());
mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) => source.Select(context.Map<SearchResultEntity>).ToList());
mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
}
// Umbraco.Code.MapAll -Alias
@@ -45,7 +45,7 @@ namespace Umbraco.Web.Models.Mapping
if (!(target is List<Language> list))
throw new NotSupportedException($"{nameof(target)} must be a List<Language>.");
var temp = source.Select(context.Map<ILanguage, Language>).ToList();
var temp = context.MapEnumerable<ILanguage, Language>(source);
//Put the default language first in the list & then sort rest by a-z
var defaultLang = temp.SingleOrDefault(x => x.IsDefault);
@@ -23,7 +23,7 @@ namespace Umbraco.Web.Models.Mapping
public void DefineMaps(UmbracoMapper mapper)
{
mapper.Define<IMacro, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<IMacro, IEnumerable<MacroParameter>>((source, context) => source.Properties.Values.Select(context.Map<MacroParameter>).ToList());
mapper.Define<IMacro, IEnumerable<MacroParameter>>((source, context) => context.MapEnumerable<IMacroProperty, MacroParameter>(source.Properties.Values));
mapper.Define<IMacroProperty, MacroParameter>((source, context) => new MacroParameter(), Map);
}
@@ -42,7 +42,7 @@ namespace Umbraco.Web.Models.Mapping
// Umbraco.Code.MapAll
private static void Map(IMedia source, ContentPropertyCollectionDto target, MapperContext context)
{
target.Properties = source.Properties.Select(context.Map<ContentPropertyDto>);
target.Properties = context.MapEnumerable<Property, ContentPropertyDto>(source.Properties);
}
// Umbraco.Code.MapAll -Properties -Errors -Edited -Updater -Alias -IsContainer
@@ -84,7 +84,7 @@ namespace Umbraco.Web.Models.Mapping
target.Owner = _commonMapper.GetOwner(source, context);
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Properties = source.Properties.Select(context.Map<ContentPropertyBasic>);
target.Properties = context.MapEnumerable<Property, ContentPropertyBasic>(source.Properties);
target.SortOrder = source.SortOrder;
target.State = null;
target.Trashed = source.Trashed;
@@ -111,7 +111,7 @@ namespace Umbraco.Web.Models.Mapping
target.Owner = _commonMapper.GetOwner(source, context);
target.ParentId = source.ParentId;
target.Path = source.Path;
target.Properties = context.Map<IEnumerable<ContentPropertyBasic>>(source.Properties);
target.Properties = context.MapEnumerable<Property, ContentPropertyBasic>(source.Properties);
target.SortOrder = source.SortOrder;
target.State = null;
target.Udi = Udi.Create(Constants.UdiEntityType.Member, source.Key);
@@ -149,7 +149,7 @@ namespace Umbraco.Web.Models.Mapping
// Umbraco.Code.MapAll
private static void Map(IMember source, ContentPropertyCollectionDto target, MapperContext context)
{
target.Properties = source.Properties.Select(context.Map<ContentPropertyDto>);
target.Properties = context.MapEnumerable<Property, ContentPropertyDto>(source.Properties);
}
private MembershipScenario GetMembershipScenario()
@@ -105,7 +105,7 @@ namespace Umbraco.Web.Models.Mapping
/// <returns></returns>
protected virtual List<ContentPropertyDisplay> MapProperties(IContentBase content, List<Property> properties, MapperContext context)
{
return properties.OrderBy(x => x.PropertyType.SortOrder).Select(context.Map<ContentPropertyDisplay>).ToList();
return context.MapEnumerable<Property, ContentPropertyDisplay>(properties.OrderBy(x => x.PropertyType.SortOrder));
}
}
@@ -10,6 +10,7 @@ using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Sections;
using Umbraco.Core.Services;
using Umbraco.Web.Actions;
using Umbraco.Web.Services;
@@ -215,7 +216,7 @@ namespace Umbraco.Web.Models.Mapping
//Important! Currently we are never mapping to multiple UserGroupDisplay objects but if we start doing that
// this will cause an N+1 and we'll need to change how this works.
var users = _userService.GetAllInGroup(source.Id);
target.Users = context.Map<IEnumerable<UserBasic>>(users);
target.Users = context.MapEnumerable<IUser, UserBasic>(users);
//Deal with assigned permissions:
@@ -286,7 +287,7 @@ namespace Umbraco.Web.Models.Mapping
target.StartContentIds = GetStartNodes(source.StartContentIds.ToArray(), UmbracoObjectTypes.Document, "content/contentRoot", context);
target.StartMediaIds = GetStartNodes(source.StartMediaIds.ToArray(), UmbracoObjectTypes.Media, "media/mediaRoot", context);
target.UpdateDate = source.UpdateDate;
target.UserGroups = source.Groups.Select(context.Map<UserGroupBasic>);
target.UserGroups = context.MapEnumerable<IReadOnlyUserGroup, UserGroupBasic>(source.Groups);
target.Username = source.Username;
target.UserState = source.UserState;
}
@@ -307,7 +308,7 @@ namespace Umbraco.Web.Models.Mapping
target.Name = source.Name;
target.ParentId = -1;
target.Path = "-1," + source.Id;
target.UserGroups = source.Groups.Select(context.Map<UserGroupBasic>);
target.UserGroups = context.MapEnumerable<IReadOnlyUserGroup, UserGroupBasic>(source.Groups);
target.Username = source.Username;
target.UserState = source.UserState;
}
@@ -336,7 +337,7 @@ namespace Umbraco.Web.Models.Mapping
private void MapUserGroupBasic(UserGroupBasic target, IEnumerable<string> sourceAllowedSections, int? sourceStartContentId, int? sourceStartMediaId, MapperContext context)
{
var allSections = _sectionService.GetSections();
target.Sections = allSections.Where(x => sourceAllowedSections.Contains(x.Alias)).Select(context.Map<Section>);
target.Sections = context.MapEnumerable<ISection, Section>(allSections.Where(x => sourceAllowedSections.Contains(x.Alias)));
if (sourceStartMediaId > 0)
target.MediaStartNode = context.Map<EntityBasic>(_entityService.Get(sourceStartMediaId.Value, UmbracoObjectTypes.Media));
@@ -387,7 +388,7 @@ namespace Umbraco.Web.Models.Mapping
startNodes.Add(CreateRootNode(_textService.Localize(localizedKey)));
var mediaItems = _entityService.GetAll(objectType, startNodeIds);
startNodes.AddRange(context.Map<IEnumerable<EntityBasic>>(mediaItems));
startNodes.AddRange(context.MapEnumerable<IEntitySlim, EntityBasic>(mediaItems));
return startNodes;
}
+7 -6
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
@@ -66,37 +67,37 @@ namespace Umbraco.Web
/// <inheritdoc />
public IEnumerable<TagModel> GetAllTags(string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllTags(group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllTags(group, culture));
}
/// <inheritdoc />
public IEnumerable<TagModel> GetAllContentTags(string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllContentTags(group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllContentTags(group, culture));
}
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMediaTags(string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllMediaTags(group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMediaTags(group, culture));
}
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMemberTags(string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetAllMemberTags(group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMemberTags(group, culture));
}
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
}
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForEntity(int contentId, string group = null, string culture = null)
{
return _mapper.Map<IEnumerable<TagModel>>(_tagService.GetTagsForEntity(contentId, group, culture));
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForEntity(contentId, group, culture));
}
}
}
@@ -138,7 +138,7 @@ namespace Umbraco.Web.Trees
{
var results = Services.EntityService.GetPagedDescendants(UmbracoObjectTypes.DocumentType, pageIndex, pageSize, out totalFound,
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains(query)));
return Mapper.Map<IEnumerable<SearchResultEntity>>(results);
return Mapper.MapEnumerable<IEntitySlim, SearchResultEntity>(results);
}
}
}
@@ -143,7 +143,7 @@ namespace Umbraco.Web.Trees
{
var results = Services.EntityService.GetPagedDescendants(UmbracoObjectTypes.DataType, pageIndex, pageSize, out totalFound,
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains(query)));
return Mapper.Map<IEnumerable<SearchResultEntity>>(results);
return Mapper.MapEnumerable<IEntitySlim, SearchResultEntity>(results);
}
}
}
@@ -120,7 +120,7 @@ namespace Umbraco.Web.Trees
{
var results = Services.EntityService.GetPagedDescendants(UmbracoObjectTypes.MediaType, pageIndex, pageSize, out totalFound,
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains(query)));
return Mapper.Map<IEnumerable<SearchResultEntity>>(results);
return Mapper.MapEnumerable<IEntitySlim, SearchResultEntity>(results);
}
}
}
@@ -122,7 +122,7 @@ namespace Umbraco.Web.Trees
{
var results = Services.EntityService.GetPagedDescendants(UmbracoObjectTypes.Template, pageIndex, pageSize, out totalFound,
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains(query)));
return Mapper.Map<IEnumerable<SearchResultEntity>>(results);
return Mapper.MapEnumerable<IEntitySlim, SearchResultEntity>(results);
}
}
}