From eff70db87e4c2dc506573ca9e5ceae62f07c3854 Mon Sep 17 00:00:00 2001 From: Ismail Mayat Date: Fri, 29 Jun 2018 11:48:47 +0100 Subject: [PATCH] another class and its callers made static --- .../Persistence/Factories/MacroFactory.cs | 152 +++++++++--------- .../Implement/ExternalLoginRepository.cs | 14 +- .../Repositories/Implement/MacroRepository.cs | 17 +- 3 files changed, 88 insertions(+), 95 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Factories/MacroFactory.cs b/src/Umbraco.Core/Persistence/Factories/MacroFactory.cs index 3963c591f0..5cf2d0ea1c 100644 --- a/src/Umbraco.Core/Persistence/Factories/MacroFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/MacroFactory.cs @@ -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 BuildPropertyDtos(IMacro entity) - { - var list = new List(); - 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 BuildPropertyDtos(IMacro entity) + { + var list = new List(); + 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; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs index 1678fd6a46..ce9a44f595 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs @@ -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 ConvertFromDtos(IEnumerable 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); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs index c492d9be81..546be0b4a8 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs @@ -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 ConvertFromDtos(IEnumerable 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);