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

57 lines
2.4 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-03-24 12:01:23 +01:00
internal class RelationMapperProfile : IMapperProfile
2015-01-06 15:36:14 +11:00
{
2019-03-24 12:01:23 +01:00
public void SetMaps(Mapper mapper)
2015-01-06 15:36:14 +11:00
{
2019-03-25 09:03:46 +01:00
mapper.Define<IRelationType, RelationTypeDisplay>(source => new RelationTypeDisplay(), Map);
mapper.Define<IRelation, RelationDisplay>(source => new RelationDisplay(), Map);
mapper.Define<RelationTypeSave, IRelationType>(Map);
2019-03-24 12:01:23 +01:00
}
2018-10-28 19:04:00 +00:00
2019-03-24 12:01:23 +01:00
// Umbraco.Code.MapAll -Icon -Trashed -Alias -AdditionalData
// Umbraco.Code.MapAll -Relations -ParentId -Notifications
private static void Map(IRelationType source, RelationTypeDisplay target)
{
target.ChildObjectType = source.ChildObjectType;
target.Id = source.Id;
target.IsBidirectional = source.IsBidirectional;
target.Key = source.Key;
target.Name = source.Name;
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
private static void Map(IRelation source, RelationDisplay target)
{
target.ChildId = source.ChildId;
target.Comment = source.Comment;
target.CreateDate = source.CreateDate;
target.ParentId = source.ParentId;
}
// Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate
private static void Map(RelationTypeSave source, IRelationType target)
{
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
}