Files
Umbraco-CMS/src/Umbraco.Web/Models/Mapping/RelationMapDefinition.cs

58 lines
2.5 KiB
C#
Raw Normal View History

2019-03-24 12:01:23 +01:00
using Umbraco.Core;
using Umbraco.Core.Mapping;
2015-01-06 15:36:14 +11:00
using Umbraco.Core.Models;
2018-10-28 19:04:00 +00:00
using Umbraco.Web.Models.ContentEditing;
2015-01-06 15:36:14 +11:00
namespace Umbraco.Web.Models.Mapping
{
2019-04-03 10:39:49 +02:00
internal class RelationMapDefinition : IMapDefinition
2015-01-06 15:36:14 +11:00
{
2019-04-03 10:39:49 +02:00
public void DefineMaps(UmbracoMapper mapper)
2015-01-06 15:36:14 +11:00
{
2019-03-26 10:39:50 +01:00
mapper.Define<IRelationType, RelationTypeDisplay>((source, context) => new RelationTypeDisplay(), Map);
mapper.Define<IRelation, RelationDisplay>((source, context) => new RelationDisplay(), Map);
2019-03-25 09:03:46 +01:00
mapper.Define<RelationTypeSave, IRelationType>(Map);
2019-03-24 12:01:23 +01:00
}
2018-10-28 19:04:00 +00:00
// Umbraco.Code.MapAll -Icon -Trashed -AdditionalData
2019-03-24 12:01:23 +01:00
// Umbraco.Code.MapAll -Relations -ParentId -Notifications
2019-03-26 10:39:50 +01:00
private static void Map(IRelationType source, RelationTypeDisplay target, MapperContext context)
2019-03-24 12:01:23 +01:00
{
target.ChildObjectType = source.ChildObjectType;
target.Id = source.Id;
target.IsBidirectional = source.IsBidirectional;
target.Key = source.Key;
target.Name = source.Name;
target.Alias = source.Alias;
2019-03-24 12:01:23 +01:00
target.ParentObjectType = source.ParentObjectType;
target.Udi = Udi.Create(Constants.UdiEntityType.RelationType, source.Key);
target.Path = "-1," + source.Id;
2018-10-28 19:04:00 +00:00
2019-03-24 12:01:23 +01:00
// Set the "friendly" names for the parent and child object types
target.ParentObjectTypeName = ObjectTypes.GetUmbracoObjectType(source.ParentObjectType).GetFriendlyName();
target.ChildObjectTypeName = ObjectTypes.GetUmbracoObjectType(source.ChildObjectType).GetFriendlyName();
}
2018-11-15 22:22:15 +00:00
2019-03-24 12:01:23 +01:00
// Umbraco.Code.MapAll -ParentName -ChildName
2019-03-26 10:39:50 +01:00
private static void Map(IRelation source, RelationDisplay target, MapperContext context)
2019-03-24 12:01:23 +01:00
{
target.ChildId = source.ChildId;
target.Comment = source.Comment;
target.CreateDate = source.CreateDate;
target.ParentId = source.ParentId;
}
// Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate
2019-03-26 10:39:50 +01:00
private static void Map(RelationTypeSave source, IRelationType target, MapperContext context)
2019-03-24 12:01:23 +01:00
{
target.Alias = source.Alias;
target.ChildObjectType = source.ChildObjectType;
target.Id = source.Id.TryConvertTo<int>().Result;
target.IsBidirectional = source.IsBidirectional;
target.Key = source.Key;
target.Name = source.Name;
target.ParentObjectType = source.ParentObjectType;
2015-01-06 15:36:14 +11:00
}
}
2017-07-20 11:21:28 +02:00
}