another class and its callers made static
This commit is contained in:
@@ -1,77 +1,77 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal class MacroFactory
|
||||
{
|
||||
public IMacro BuildEntity(MacroDto dto)
|
||||
{
|
||||
var model = new Macro(dto.Id, dto.UniqueId, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.MacroSource, (MacroTypes)dto.MacroType);
|
||||
|
||||
try
|
||||
{
|
||||
model.DisableChangeTracking();
|
||||
|
||||
foreach (var p in dto.MacroPropertyDtos.EmptyNull())
|
||||
{
|
||||
model.Properties.Add(new MacroProperty(p.Id, p.UniqueId, p.Alias, p.Name, p.SortOrder, p.EditorAlias));
|
||||
}
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
}
|
||||
finally
|
||||
{
|
||||
model.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public MacroDto BuildDto(IMacro entity)
|
||||
{
|
||||
var dto = new MacroDto
|
||||
{
|
||||
UniqueId = entity.Key,
|
||||
Alias = entity.Alias,
|
||||
CacheByPage = entity.CacheByPage,
|
||||
CachePersonalized = entity.CacheByMember,
|
||||
DontRender = entity.DontRender,
|
||||
Name = entity.Name,
|
||||
MacroSource = entity.MacroSource,
|
||||
RefreshRate = entity.CacheDuration,
|
||||
UseInEditor = entity.UseInEditor,
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class MacroFactory
|
||||
{
|
||||
public static IMacro BuildEntity(MacroDto dto)
|
||||
{
|
||||
var model = new Macro(dto.Id, dto.UniqueId, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.MacroSource, (MacroTypes)dto.MacroType);
|
||||
|
||||
try
|
||||
{
|
||||
model.DisableChangeTracking();
|
||||
|
||||
foreach (var p in dto.MacroPropertyDtos.EmptyNull())
|
||||
{
|
||||
model.Properties.Add(new MacroProperty(p.Id, p.UniqueId, p.Alias, p.Name, p.SortOrder, p.EditorAlias));
|
||||
}
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
}
|
||||
finally
|
||||
{
|
||||
model.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
public static MacroDto BuildDto(IMacro entity)
|
||||
{
|
||||
var dto = new MacroDto
|
||||
{
|
||||
UniqueId = entity.Key,
|
||||
Alias = entity.Alias,
|
||||
CacheByPage = entity.CacheByPage,
|
||||
CachePersonalized = entity.CacheByMember,
|
||||
DontRender = entity.DontRender,
|
||||
Name = entity.Name,
|
||||
MacroSource = entity.MacroSource,
|
||||
RefreshRate = entity.CacheDuration,
|
||||
UseInEditor = entity.UseInEditor,
|
||||
MacroPropertyDtos = BuildPropertyDtos(entity),
|
||||
MacroType = (int)entity.MacroType
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private List<MacroPropertyDto> BuildPropertyDtos(IMacro entity)
|
||||
{
|
||||
var list = new List<MacroPropertyDto>();
|
||||
foreach (var p in entity.Properties)
|
||||
{
|
||||
var text = new MacroPropertyDto
|
||||
{
|
||||
UniqueId = p.Key,
|
||||
Alias = p.Alias,
|
||||
Name = p.Name,
|
||||
Macro = entity.Id,
|
||||
SortOrder = (byte)p.SortOrder,
|
||||
EditorAlias = p.EditorAlias,
|
||||
Id = p.Id
|
||||
};
|
||||
|
||||
list.Add(text);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
MacroType = (int)entity.MacroType
|
||||
};
|
||||
|
||||
if (entity.HasIdentity)
|
||||
dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static List<MacroPropertyDto> BuildPropertyDtos(IMacro entity)
|
||||
{
|
||||
var list = new List<MacroPropertyDto>();
|
||||
foreach (var p in entity.Properties)
|
||||
{
|
||||
var text = new MacroPropertyDto
|
||||
{
|
||||
UniqueId = p.Key,
|
||||
Alias = p.Alias,
|
||||
Name = p.Name,
|
||||
Macro = entity.Id,
|
||||
SortOrder = (byte)p.SortOrder,
|
||||
EditorAlias = p.EditorAlias,
|
||||
Id = p.Id
|
||||
};
|
||||
|
||||
list.Add(text);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
if (dto == null)
|
||||
return null;
|
||||
|
||||
var factory = new ExternalLoginFactory();
|
||||
var entity = factory.BuildEntity(dto);
|
||||
var entity = ExternalLoginFactory.BuildEntity(dto);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
@@ -85,8 +84,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
private IEnumerable<IIdentityUserLogin> ConvertFromDtos(IEnumerable<ExternalLoginDto> dtos)
|
||||
{
|
||||
var factory = new ExternalLoginFactory();
|
||||
foreach (var entity in dtos.Select(factory.BuildEntity))
|
||||
foreach (var entity in dtos.Select(ExternalLoginFactory.BuildEntity))
|
||||
{
|
||||
// reset dirty initial properties (U4-1946)
|
||||
((BeingDirtyBase)entity).ResetDirtyProperties(false);
|
||||
@@ -143,8 +141,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
((EntityBase)entity).AddingEntity();
|
||||
|
||||
var factory = new ExternalLoginFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
var dto = ExternalLoginFactory.BuildDto(entity);
|
||||
|
||||
var id = Convert.ToInt32(Database.Insert(dto));
|
||||
entity.Id = id;
|
||||
@@ -155,9 +152,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
protected override void PersistUpdatedItem(IIdentityUserLogin entity)
|
||||
{
|
||||
((EntityBase)entity).UpdatingEntity();
|
||||
|
||||
var factory = new ExternalLoginFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
|
||||
var dto = ExternalLoginFactory.BuildDto(entity);
|
||||
|
||||
Database.Update(dto);
|
||||
|
||||
|
||||
@@ -40,9 +40,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
if (macroDto == null)
|
||||
return null;
|
||||
|
||||
var factory = new MacroFactory();
|
||||
var entity = factory.BuildEntity(macroDto);
|
||||
|
||||
var entity = MacroFactory.BuildEntity(macroDto);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
((BeingDirtyBase)entity).ResetDirtyProperties(false);
|
||||
@@ -79,8 +78,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
private IEnumerable<IMacro> ConvertFromDtos(IEnumerable<MacroDto> dtos)
|
||||
{
|
||||
var factory = new MacroFactory();
|
||||
foreach (var entity in dtos.Select(factory.BuildEntity))
|
||||
|
||||
foreach (var entity in dtos.Select(MacroFactory.BuildEntity))
|
||||
{
|
||||
// reset dirty initial properties (U4-1946)
|
||||
((BeingDirtyBase)entity).ResetDirtyProperties(false);
|
||||
@@ -135,8 +134,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
((EntityBase)entity).AddingEntity();
|
||||
|
||||
var factory = new MacroFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
var dto = MacroFactory.BuildDto(entity);
|
||||
|
||||
var id = Convert.ToInt32(Database.Insert(dto));
|
||||
entity.Id = id;
|
||||
@@ -155,9 +153,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
protected override void PersistUpdatedItem(IMacro entity)
|
||||
{
|
||||
((EntityBase)entity).UpdatingEntity();
|
||||
|
||||
var factory = new MacroFactory();
|
||||
var dto = factory.BuildDto(entity);
|
||||
;
|
||||
var dto = MacroFactory.BuildDto(entity);
|
||||
|
||||
Database.Update(dto);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user