make static update callers

This commit is contained in:
Ismail Mayat
2018-06-29 12:07:32 +01:00
parent 580ea66ea5
commit d1273f2ba9
2 changed files with 64 additions and 66 deletions

View File

@@ -1,54 +1,54 @@
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories
{
internal class RelationTypeFactory
{
#region Implementation of IEntityFactory<RelationType,RelationTypeDto>
public IRelationType BuildEntity(RelationTypeDto dto)
{
var entity = new RelationType(dto.ChildObjectType, dto.ParentObjectType, dto.Alias);
try
{
entity.DisableChangeTracking();
entity.Id = dto.Id;
entity.Key = dto.UniqueId;
entity.IsBidirectional = dto.Dual;
entity.Name = dto.Name;
// reset dirty initial properties (U4-1946)
entity.ResetDirtyProperties(false);
return entity;
}
finally
{
entity.EnableChangeTracking();
}
}
public RelationTypeDto BuildDto(IRelationType entity)
{
var dto = new RelationTypeDto
{
Alias = entity.Alias,
ChildObjectType = entity.ChildObjectType,
Dual = entity.IsBidirectional,
Name = entity.Name,
ParentObjectType = entity.ParentObjectType,
UniqueId = entity.Key
};
if (entity.HasIdentity)
{
dto.Id = entity.Id;
}
return dto;
}
#endregion
}
}
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Factories
{
internal static class RelationTypeFactory
{
#region Implementation of IEntityFactory<RelationType,RelationTypeDto>
public static IRelationType BuildEntity(RelationTypeDto dto)
{
var entity = new RelationType(dto.ChildObjectType, dto.ParentObjectType, dto.Alias);
try
{
entity.DisableChangeTracking();
entity.Id = dto.Id;
entity.Key = dto.UniqueId;
entity.IsBidirectional = dto.Dual;
entity.Name = dto.Name;
// reset dirty initial properties (U4-1946)
entity.ResetDirtyProperties(false);
return entity;
}
finally
{
entity.EnableChangeTracking();
}
}
public static RelationTypeDto BuildDto(IRelationType entity)
{
var dto = new RelationTypeDto
{
Alias = entity.Alias,
ChildObjectType = entity.ChildObjectType,
Dual = entity.IsBidirectional,
Name = entity.Name,
ParentObjectType = entity.ParentObjectType,
UniqueId = entity.Key
};
if (entity.HasIdentity)
{
dto.Id = entity.Id;
}
return dto;
}
#endregion
}
}

View File

@@ -55,8 +55,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
throw new NotImplementedException();
var dtos = Database.Fetch<RelationTypeDto>(sql);
var factory = new RelationTypeFactory();
return dtos.Select(x => DtoToEntity(x, factory));
return dtos.Select(x => DtoToEntity(x));
}
public IEnumerable<IRelationType> GetMany(params Guid[] ids)
@@ -75,13 +75,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var sql = translator.Translate();
var dtos = Database.Fetch<RelationTypeDto>(sql);
var factory = new RelationTypeFactory();
return dtos.Select(x => DtoToEntity(x, factory));
return dtos.Select(x => DtoToEntity(x));
}
private static IRelationType DtoToEntity(RelationTypeDto dto, RelationTypeFactory factory)
private static IRelationType DtoToEntity(RelationTypeDto dto)
{
var entity = factory.BuildEntity(dto);
var entity = RelationTypeFactory.BuildEntity(dto);
// reset dirty initial properties (U4-1946)
((BeingDirtyBase) entity).ResetDirtyProperties(false);
@@ -134,9 +134,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistNewItem(IRelationType entity)
{
((EntityBase)entity).AddingEntity();
var factory = new RelationTypeFactory();
var dto = factory.BuildDto(entity);
var dto = RelationTypeFactory.BuildDto(entity);
var id = Convert.ToInt32(Database.Insert(dto));
entity.Id = id;
@@ -147,9 +146,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistUpdatedItem(IRelationType entity)
{
((EntityBase)entity).UpdatingEntity();
var factory = new RelationTypeFactory();
var dto = factory.BuildDto(entity);
var dto = RelationTypeFactory.BuildDto(entity);
Database.Update(dto);
entity.ResetDirtyProperties();