Adds Relation and RelationType factories U4-987 and U4-986
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class Relation : Entity
|
||||
public class Relation : Entity, IAggregateRoot
|
||||
{
|
||||
//NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity
|
||||
private int _parentId;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class RelationType : Entity
|
||||
public class RelationType : Entity, IAggregateRoot
|
||||
{
|
||||
private string _name;
|
||||
private string _alias;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal interface IEntityFactory<TEntity, TDto>
|
||||
where TEntity : class
|
||||
|
||||
49
src/Umbraco.Core/Persistence/Factories/RelationFactory.cs
Normal file
49
src/Umbraco.Core/Persistence/Factories/RelationFactory.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class RelationFactory : IEntityFactory<Relation, RelationDto>
|
||||
{
|
||||
private readonly RelationType _relationType;
|
||||
|
||||
public RelationFactory(RelationType relationType)
|
||||
{
|
||||
_relationType = relationType;
|
||||
}
|
||||
|
||||
#region Implementation of IEntityFactory<Relation,RelationDto>
|
||||
|
||||
public Relation BuildEntity(RelationDto dto)
|
||||
{
|
||||
var entity = new Relation(dto.ParentId, dto.ChildId)
|
||||
{
|
||||
Comment = dto.Comment,
|
||||
CreateDate = dto.Datetime,
|
||||
Id = dto.Id,
|
||||
UpdateDate = dto.Datetime,
|
||||
RelationType = _relationType
|
||||
};
|
||||
return entity;
|
||||
}
|
||||
|
||||
public RelationDto BuildDto(Relation entity)
|
||||
{
|
||||
var dto = new RelationDto
|
||||
{
|
||||
ChildId = entity.ChildId,
|
||||
Comment = entity.Comment,
|
||||
Datetime = entity.CreateDate,
|
||||
ParentId = entity.ParentId,
|
||||
RelationType = _relationType.Id
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class RelationTypeFactory : IEntityFactory<RelationType, RelationTypeDto>
|
||||
{
|
||||
#region Implementation of IEntityFactory<RelationType,RelationTypeDto>
|
||||
|
||||
public RelationType BuildEntity(RelationTypeDto dto)
|
||||
{
|
||||
var entity = new RelationType(dto.ChildObjectType, dto.ParentObjectType, dto.Alias)
|
||||
{
|
||||
Id = dto.Id,
|
||||
IsBidirectional = dto.Dual,
|
||||
Name = dto.Name
|
||||
};
|
||||
return entity;
|
||||
}
|
||||
|
||||
public RelationTypeDto BuildDto(RelationType entity)
|
||||
{
|
||||
var dto = new RelationTypeDto
|
||||
{
|
||||
Alias = entity.Alias,
|
||||
ChildObjectType = entity.ChildObjectType,
|
||||
Dual = entity.IsBidirectional,
|
||||
Name = entity.Name,
|
||||
ParentObjectType = entity.ParentObjectType
|
||||
};
|
||||
if(entity.HasIdentity)
|
||||
dto.Id = entity.Id;
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user