Adds Relation and RelationType factories U4-987 and U4-986

This commit is contained in:
Morten@Thinkpad-X220
2012-10-09 06:01:04 -02:00
parent 1b0c543176
commit 14e827d749
5 changed files with 91 additions and 5 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View 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
}
}

View File

@@ -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
}
}