diff --git a/src/Umbraco.Core/Persistence/Factories/ContentTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/ContentTypeFactory.cs index f788880d34..38a1aa2aab 100644 --- a/src/Umbraco.Core/Persistence/Factories/ContentTypeFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/ContentTypeFactory.cs @@ -1,163 +1,162 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Entities; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - // factory for - // IContentType (document types) - // IMediaType (media types) - // IMemberType (member types) - // - internal class ContentTypeFactory - { - #region IContentType - - public IContentType BuildContentTypeEntity(ContentTypeDto dto) - { - var contentType = new ContentType(dto.NodeDto.ParentId); - - try - { - contentType.DisableChangeTracking(); - - BuildCommonEntity(contentType, dto); - - // reset dirty initial properties (U4-1946) - contentType.ResetDirtyProperties(false); - return contentType; - } - finally - { - contentType.EnableChangeTracking(); - } - } - - #endregion - - #region IMediaType - - public IMediaType BuildMediaTypeEntity(ContentTypeDto dto) - { - var contentType = new MediaType(dto.NodeDto.ParentId); - try - { - contentType.DisableChangeTracking(); - - BuildCommonEntity(contentType, dto); - - // reset dirty initial properties (U4-1946) - contentType.ResetDirtyProperties(false); - } - finally - { - contentType.EnableChangeTracking(); - } - - return contentType; - } - - #endregion - - #region IMemberType - - public IMemberType BuildMemberTypeEntity(ContentTypeDto dto) - { - throw new NotImplementedException(); - } - - public IEnumerable BuildMemberTypeDtos(IMemberType entity) - { - var memberType = entity as MemberType; - if (memberType == null || memberType.PropertyTypes.Any() == false) - return Enumerable.Empty(); - - var dtos = memberType.PropertyTypes.Select(x => new MemberTypeDto - { - NodeId = entity.Id, - PropertyTypeId = x.Id, - CanEdit = memberType.MemberCanEditProperty(x.Alias), - ViewOnProfile = memberType.MemberCanViewProperty(x.Alias), - IsSensitive = memberType.IsSensitiveProperty(x.Alias) - }).ToList(); - return dtos; - } - - #endregion - - #region Common - - private static void BuildCommonEntity(ContentTypeBase entity, ContentTypeDto dto) - { - entity.Id = dto.NodeDto.NodeId; - entity.Key = dto.NodeDto.UniqueId; - entity.Alias = dto.Alias; - entity.Name = dto.NodeDto.Text; - entity.Icon = dto.Icon; - entity.Thumbnail = dto.Thumbnail; - entity.SortOrder = dto.NodeDto.SortOrder; - entity.Description = dto.Description; - entity.CreateDate = dto.NodeDto.CreateDate; - entity.Path = dto.NodeDto.Path; - entity.Level = dto.NodeDto.Level; - entity.CreatorId = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId; - entity.AllowedAsRoot = dto.AllowAtRoot; - entity.IsContainer = dto.IsContainer; - entity.Trashed = dto.NodeDto.Trashed; - entity.Variations = (ContentVariation) dto.Variations; - } - - public ContentTypeDto BuildContentTypeDto(IContentTypeBase entity) - { - Guid nodeObjectType; - if (entity is IContentType) - nodeObjectType = Constants.ObjectTypes.DocumentType; - else if (entity is IMediaType) - nodeObjectType = Constants.ObjectTypes.MediaType; - else if (entity is IMemberType) - nodeObjectType = Constants.ObjectTypes.MemberType; - else - throw new Exception("Invalid entity."); - - var contentTypeDto = new ContentTypeDto - { - Alias = entity.Alias, - Description = entity.Description, - Icon = entity.Icon, - Thumbnail = entity.Thumbnail, - NodeId = entity.Id, - AllowAtRoot = entity.AllowedAsRoot, - IsContainer = entity.IsContainer, - Variations = (byte) entity.Variations, - NodeDto = BuildNodeDto(entity, nodeObjectType) - }; - return contentTypeDto; - } - - private static NodeDto BuildNodeDto(IUmbracoEntity entity, Guid nodeObjectType) - { - var nodeDto = new NodeDto - { - CreateDate = entity.CreateDate, - NodeId = entity.Id, - Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)), - NodeObjectType = nodeObjectType, - ParentId = entity.ParentId, - Path = entity.Path, - SortOrder = entity.SortOrder, - Text = entity.Name, - Trashed = false, - UniqueId = entity.Key, - UserId = entity.CreatorId - }; - return nodeDto; - } - - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Entities; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + // factory for + // IContentType (document types) + // IMediaType (media types) + // IMemberType (member types) + // + internal static class ContentTypeFactory + { + #region IContentType + + public static IContentType BuildContentTypeEntity(ContentTypeDto dto) + { + var contentType = new ContentType(dto.NodeDto.ParentId); + + try + { + contentType.DisableChangeTracking(); + + BuildCommonEntity(contentType, dto); + + // reset dirty initial properties (U4-1946) + contentType.ResetDirtyProperties(false); + return contentType; + } + finally + { + contentType.EnableChangeTracking(); + } + } + + #endregion + + #region IMediaType + + public static IMediaType BuildMediaTypeEntity(ContentTypeDto dto) + { + var contentType = new MediaType(dto.NodeDto.ParentId); + try + { + contentType.DisableChangeTracking(); + + BuildCommonEntity(contentType, dto); + + // reset dirty initial properties (U4-1946) + contentType.ResetDirtyProperties(false); + } + finally + { + contentType.EnableChangeTracking(); + } + + return contentType; + } + + #endregion + + #region IMemberType + + public static IMemberType BuildMemberTypeEntity(ContentTypeDto dto) + { + throw new NotImplementedException(); + } + + public static IEnumerable BuildMemberTypeDtos(IMemberType entity) + { + var memberType = entity as MemberType; + if (memberType == null || memberType.PropertyTypes.Any() == false) + return Enumerable.Empty(); + + var dtos = memberType.PropertyTypes.Select(x => new MemberTypeDto + { + NodeId = entity.Id, + PropertyTypeId = x.Id, + CanEdit = memberType.MemberCanEditProperty(x.Alias), + ViewOnProfile = memberType.MemberCanViewProperty(x.Alias), + IsSensitive = memberType.IsSensitiveProperty(x.Alias) + }).ToList(); + return dtos; + } + + #endregion + + #region Common + + private static void BuildCommonEntity(ContentTypeBase entity, ContentTypeDto dto) + { + entity.Id = dto.NodeDto.NodeId; + entity.Key = dto.NodeDto.UniqueId; + entity.Alias = dto.Alias; + entity.Name = dto.NodeDto.Text; + entity.Icon = dto.Icon; + entity.Thumbnail = dto.Thumbnail; + entity.SortOrder = dto.NodeDto.SortOrder; + entity.Description = dto.Description; + entity.CreateDate = dto.NodeDto.CreateDate; + entity.Path = dto.NodeDto.Path; + entity.Level = dto.NodeDto.Level; + entity.CreatorId = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId; + entity.AllowedAsRoot = dto.AllowAtRoot; + entity.IsContainer = dto.IsContainer; + entity.Trashed = dto.NodeDto.Trashed; + entity.Variations = (ContentVariation) dto.Variations; + } + + public static ContentTypeDto BuildContentTypeDto(IContentTypeBase entity) + { + Guid nodeObjectType; + if (entity is IContentType) + nodeObjectType = Constants.ObjectTypes.DocumentType; + else if (entity is IMediaType) + nodeObjectType = Constants.ObjectTypes.MediaType; + else if (entity is IMemberType) + nodeObjectType = Constants.ObjectTypes.MemberType; + else + throw new Exception("Invalid entity."); + + var contentTypeDto = new ContentTypeDto + { + Alias = entity.Alias, + Description = entity.Description, + Icon = entity.Icon, + Thumbnail = entity.Thumbnail, + NodeId = entity.Id, + AllowAtRoot = entity.AllowedAsRoot, + IsContainer = entity.IsContainer, + Variations = (byte) entity.Variations, + NodeDto = BuildNodeDto(entity, nodeObjectType) + }; + return contentTypeDto; + } + + private static NodeDto BuildNodeDto(IUmbracoEntity entity, Guid nodeObjectType) + { + var nodeDto = new NodeDto + { + CreateDate = entity.CreateDate, + NodeId = entity.Id, + Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)), + NodeObjectType = nodeObjectType, + ParentId = entity.ParentId, + Path = entity.Path, + SortOrder = entity.SortOrder, + Text = entity.Name, + Trashed = false, + UniqueId = entity.Key, + UserId = entity.CreatorId + }; + return nodeDto; + } + + #endregion + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs b/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs index e84b1c96e2..8994026ccb 100644 --- a/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs @@ -4,11 +4,11 @@ using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Factories { - internal class DictionaryItemFactory + internal static class DictionaryItemFactory { #region Implementation of IEntityFactory - public IDictionaryItem BuildEntity(DictionaryDto dto) + public static IDictionaryItem BuildEntity(DictionaryDto dto) { var item = new DictionaryItem(dto.Parent, dto.Key); @@ -29,7 +29,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public DictionaryDto BuildDto(IDictionaryItem entity) + public static DictionaryDto BuildDto(IDictionaryItem entity) { return new DictionaryDto { @@ -43,7 +43,7 @@ namespace Umbraco.Core.Persistence.Factories #endregion - private List BuildLanguageTextDtos(IDictionaryItem entity) + private static List BuildLanguageTextDtos(IDictionaryItem entity) { var list = new List(); foreach (var translation in entity.Translations) diff --git a/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs b/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs index a4075e03e2..5325813dbf 100644 --- a/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs @@ -1,55 +1,48 @@ -using System; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class DictionaryTranslationFactory - { - private readonly Guid _uniqueId; - - public DictionaryTranslationFactory(Guid uniqueId) - { - _uniqueId = uniqueId; - } - - #region Implementation of IEntityFactory - - public IDictionaryTranslation BuildEntity(LanguageTextDto dto) - { - var item = new DictionaryTranslation(dto.LanguageId, dto.Value, _uniqueId); - - try - { - item.DisableChangeTracking(); - - item.Id = dto.PrimaryKey; - - // reset dirty initial properties (U4-1946) - item.ResetDirtyProperties(false); - return item; - } - finally - { - item.EnableChangeTracking(); - } - } - - public LanguageTextDto BuildDto(IDictionaryTranslation entity) - { - var text = new LanguageTextDto - { - LanguageId = entity.LanguageId, - UniqueId = _uniqueId, - Value = entity.Value - }; - - if (entity.HasIdentity) - text.PrimaryKey = entity.Id; - - return text; - } - - #endregion - } -} +using System; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class DictionaryTranslationFactory + { + #region Implementation of IEntityFactory + + public static IDictionaryTranslation BuildEntity(LanguageTextDto dto, Guid uniqueId) + { + var item = new DictionaryTranslation(dto.LanguageId, dto.Value, uniqueId); + + try + { + item.DisableChangeTracking(); + + item.Id = dto.PrimaryKey; + + // reset dirty initial properties (U4-1946) + item.ResetDirtyProperties(false); + return item; + } + finally + { + item.EnableChangeTracking(); + } + } + + public static LanguageTextDto BuildDto(IDictionaryTranslation entity, Guid uniqueId) + { + var text = new LanguageTextDto + { + LanguageId = entity.LanguageId, + UniqueId = uniqueId, + Value = entity.Value + }; + + if (entity.HasIdentity) + text.PrimaryKey = entity.Id; + + return text; + } + + #endregion + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/ExternalLoginFactory.cs b/src/Umbraco.Core/Persistence/Factories/ExternalLoginFactory.cs index 2a8c340462..4309fe511f 100644 --- a/src/Umbraco.Core/Persistence/Factories/ExternalLoginFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/ExternalLoginFactory.cs @@ -3,9 +3,9 @@ using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Factories { - internal class ExternalLoginFactory + internal static class ExternalLoginFactory { - public IIdentityUserLogin BuildEntity(ExternalLoginDto dto) + public static IIdentityUserLogin BuildEntity(ExternalLoginDto dto) { var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId, dto.CreateDate); @@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Factories return entity; } - public ExternalLoginDto BuildDto(IIdentityUserLogin entity) + public static ExternalLoginDto BuildDto(IIdentityUserLogin entity) { var dto = new ExternalLoginDto { diff --git a/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs b/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs index f79dab1bbd..7b24411498 100644 --- a/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/LanguageFactory.cs @@ -1,26 +1,26 @@ -using System.Globalization; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class LanguageFactory - { - public ILanguage BuildEntity(LanguageDto dto) - { - var lang = new Language(dto.IsoCode) { CultureName = dto.CultureName, Id = dto.Id, IsDefaultVariantLanguage = dto.IsDefaultVariantLanguage, Mandatory = dto.Mandatory }; - // reset dirty initial properties (U4-1946) - lang.ResetDirtyProperties(false); - return lang; - } - - public LanguageDto BuildDto(ILanguage entity) - { - var dto = new LanguageDto { CultureName = entity.CultureName, IsoCode = entity.IsoCode, IsDefaultVariantLanguage = entity.IsDefaultVariantLanguage, Mandatory = entity.Mandatory }; - if (entity.HasIdentity) - dto.Id = short.Parse(entity.Id.ToString(CultureInfo.InvariantCulture)); - - return dto; - } - } -} +using System.Globalization; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class LanguageFactory + { + public static ILanguage BuildEntity(LanguageDto dto) + { + var lang = new Language(dto.IsoCode) { CultureName = dto.CultureName, Id = dto.Id, IsDefaultVariantLanguage = dto.IsDefaultVariantLanguage, Mandatory = dto.Mandatory }; + // reset dirty initial properties (U4-1946) + lang.ResetDirtyProperties(false); + return lang; + } + + public static LanguageDto BuildDto(ILanguage entity) + { + var dto = new LanguageDto { CultureName = entity.CultureName, IsoCode = entity.IsoCode, IsDefaultVariantLanguage = entity.IsDefaultVariantLanguage, Mandatory = entity.Mandatory }; + if (entity.HasIdentity) + dto.Id = short.Parse(entity.Id.ToString(CultureInfo.InvariantCulture)); + + return dto; + } + } +} 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/Factories/MemberGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/MemberGroupFactory.cs index 96c0b2fcef..cb73f3b3aa 100644 --- a/src/Umbraco.Core/Persistence/Factories/MemberGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/MemberGroupFactory.cs @@ -4,19 +4,19 @@ using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Factories { - internal class MemberGroupFactory + internal static class MemberGroupFactory { - private readonly Guid _nodeObjectTypeId; + private static readonly Guid _nodeObjectTypeId; - public MemberGroupFactory() + static MemberGroupFactory() { _nodeObjectTypeId = Constants.ObjectTypes.MemberGroup; } #region Implementation of IEntityFactory - public IMemberGroup BuildEntity(NodeDto dto) + public static IMemberGroup BuildEntity(NodeDto dto) { var group = new MemberGroup(); @@ -39,7 +39,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public NodeDto BuildDto(IMemberGroup entity) + public static NodeDto BuildDto(IMemberGroup entity) { var dto = new NodeDto { diff --git a/src/Umbraco.Core/Persistence/Factories/MemberTypeReadOnlyFactory.cs b/src/Umbraco.Core/Persistence/Factories/MemberTypeReadOnlyFactory.cs index 6f79f03c73..cbbcb03649 100644 --- a/src/Umbraco.Core/Persistence/Factories/MemberTypeReadOnlyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/MemberTypeReadOnlyFactory.cs @@ -1,202 +1,194 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; -using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Persistence.Repositories.Implement; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class MemberTypeReadOnlyFactory - { - public IMemberType BuildEntity(MemberTypeReadOnlyDto dto, out bool needsSaving) - { - var standardPropertyTypes = Constants.Conventions.Member.GetStandardPropertyTypeStubs(); - needsSaving = false; - - var memberType = new MemberType(dto.ParentId); - - try - { - memberType.DisableChangeTracking(); - - memberType.Alias = dto.Alias; - memberType.AllowedAsRoot = dto.AllowAtRoot; - memberType.CreateDate = dto.CreateDate; - memberType.CreatorId = dto.UserId.HasValue ? dto.UserId.Value : 0; - memberType.Description = dto.Description; - memberType.Icon = dto.Icon; - memberType.Id = dto.NodeId; - memberType.IsContainer = dto.IsContainer; - memberType.Key = dto.UniqueId.Value; - memberType.Level = dto.Level; - memberType.Name = dto.Text; - memberType.Path = dto.Path; - memberType.SortOrder = dto.SortOrder; - memberType.Thumbnail = dto.Thumbnail; - memberType.Trashed = dto.Trashed; - memberType.UpdateDate = dto.CreateDate; - memberType.AllowedContentTypes = Enumerable.Empty(); - - var propertyTypeGroupCollection = GetPropertyTypeGroupCollection(dto, memberType, standardPropertyTypes); - memberType.PropertyGroups = propertyTypeGroupCollection; - - var propertyTypes = GetPropertyTypes(dto, memberType, standardPropertyTypes); - - //By Convention we add 9 stnd PropertyTypes - This is only here to support loading of types that didn't have these conventions before. - foreach (var standardPropertyType in standardPropertyTypes) - { - if (dto.PropertyTypes.Any(x => x.Alias.Equals(standardPropertyType.Key))) continue; - - // beware! - // means that we can return a memberType "from database" that has some property types - // that do *not* come from the database and therefore are incomplete eg have no key, - // no id, no dataTypeDefinitionId - ouch! - better notify caller of the situation - needsSaving = true; - - //Add the standard PropertyType to the current list - propertyTypes.Add(standardPropertyType.Value); - - //Internal dictionary for adding "MemberCanEdit", "VisibleOnProfile", "IsSensitive" properties to each PropertyType - memberType.MemberTypePropertyTypes.Add(standardPropertyType.Key, - new MemberTypePropertyProfileAccess(false, false, false)); - } - memberType.NoGroupPropertyTypes = propertyTypes; - - return memberType; - } - finally - { - memberType.EnableChangeTracking(); - } - } - - private PropertyGroupCollection GetPropertyTypeGroupCollection(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary standardProps) - { - // see PropertyGroupFactory, repeating code here... - - var propertyGroups = new PropertyGroupCollection(); - foreach (var groupDto in dto.PropertyTypeGroups.Where(x => x.Id.HasValue)) - { - var group = new PropertyGroup(MemberType.IsPublishingConst); - - // if the group is defined on the current member type, - // assign its identifier, else it will be zero - if (groupDto.ContentTypeNodeId == memberType.Id) - { - // note: no idea why Id is nullable here, but better check - if (groupDto.Id.HasValue == false) - throw new Exception("GroupDto.Id has no value."); - group.Id = groupDto.Id.Value; - } - - group.Key = groupDto.UniqueId; - group.Name = groupDto.Text; - group.SortOrder = groupDto.SortOrder; - group.PropertyTypes = new PropertyTypeCollection(MemberType.IsPublishingConst); - - //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded - var localGroupDto = groupDto; - var typeDtos = dto.PropertyTypes.Where(x => x.Id.HasValue && x.Id > 0 && x.PropertyTypeGroupId.HasValue && x.PropertyTypeGroupId.Value == localGroupDto.Id.Value); - foreach (var typeDto in typeDtos) - { - //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType - memberType.MemberTypePropertyTypes.Add(typeDto.Alias, - new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive)); - - var tempGroupDto = groupDto; - - //ensures that any built-in membership properties have their correct dbtype assigned no matter - //what the underlying data type is - var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty( - typeDto.Alias, - typeDto.DbType.EnumParse(true), - standardProps); - - var propertyType = new PropertyType( - typeDto.PropertyEditorAlias, - propDbType.Result, - //This flag tells the property type that it has an explicit dbtype and that it cannot be changed - // which is what we want for the built-in properties. - propDbType.Success, - typeDto.Alias) - { - DataTypeId = typeDto.DataTypeId, - Description = typeDto.Description, - Id = typeDto.Id.Value, - Name = typeDto.Name, - Mandatory = typeDto.Mandatory, - SortOrder = typeDto.SortOrder, - ValidationRegExp = typeDto.ValidationRegExp, - PropertyGroupId = new Lazy(() => tempGroupDto.Id.Value), - CreateDate = memberType.CreateDate, - UpdateDate = memberType.UpdateDate, - Key = typeDto.UniqueId - }; - - // reset dirty initial properties (U4-1946) - propertyType.ResetDirtyProperties(false); - group.PropertyTypes.Add(propertyType); - } - - // reset dirty initial properties (U4-1946) - group.ResetDirtyProperties(false); - propertyGroups.Add(group); - } - - return propertyGroups; - } - - - - private List GetPropertyTypes(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary standardProps) - { - //Find PropertyTypes that does not belong to a PropertyTypeGroup - var propertyTypes = new List(); - foreach (var typeDto in dto.PropertyTypes.Where(x => (x.PropertyTypeGroupId.HasValue == false || x.PropertyTypeGroupId.Value == 0) && x.Id.HasValue)) - { - //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType - memberType.MemberTypePropertyTypes.Add(typeDto.Alias, - new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive)); - - //ensures that any built-in membership properties have their correct dbtype assigned no matter - //what the underlying data type is - var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty( - typeDto.Alias, - typeDto.DbType.EnumParse(true), - standardProps); - - var propertyType = new PropertyType( - typeDto.PropertyEditorAlias, - propDbType.Result, - //This flag tells the property type that it has an explicit dbtype and that it cannot be changed - // which is what we want for the built-in properties. - propDbType.Success, - typeDto.Alias) - { - DataTypeId = typeDto.DataTypeId, - Description = typeDto.Description, - Id = typeDto.Id.Value, - Mandatory = typeDto.Mandatory, - Name = typeDto.Name, - SortOrder = typeDto.SortOrder, - ValidationRegExp = typeDto.ValidationRegExp, - PropertyGroupId = null, - CreateDate = dto.CreateDate, - UpdateDate = dto.CreateDate, - Key = typeDto.UniqueId - }; - - propertyTypes.Add(propertyType); - } - return propertyTypes; - } - - public MemberTypeReadOnlyDto BuildDto(IMemberType entity) - { - throw new System.NotImplementedException(); - } - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; +using Umbraco.Core.Persistence.Repositories.Implement; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class MemberTypeReadOnlyFactory + { + public static IMemberType BuildEntity(MemberTypeReadOnlyDto dto, out bool needsSaving) + { + var standardPropertyTypes = Constants.Conventions.Member.GetStandardPropertyTypeStubs(); + needsSaving = false; + + var memberType = new MemberType(dto.ParentId); + + try + { + memberType.DisableChangeTracking(); + + memberType.Alias = dto.Alias; + memberType.AllowedAsRoot = dto.AllowAtRoot; + memberType.CreateDate = dto.CreateDate; + memberType.CreatorId = dto.UserId.HasValue ? dto.UserId.Value : 0; + memberType.Description = dto.Description; + memberType.Icon = dto.Icon; + memberType.Id = dto.NodeId; + memberType.IsContainer = dto.IsContainer; + memberType.Key = dto.UniqueId.Value; + memberType.Level = dto.Level; + memberType.Name = dto.Text; + memberType.Path = dto.Path; + memberType.SortOrder = dto.SortOrder; + memberType.Thumbnail = dto.Thumbnail; + memberType.Trashed = dto.Trashed; + memberType.UpdateDate = dto.CreateDate; + memberType.AllowedContentTypes = Enumerable.Empty(); + + var propertyTypeGroupCollection = GetPropertyTypeGroupCollection(dto, memberType, standardPropertyTypes); + memberType.PropertyGroups = propertyTypeGroupCollection; + + var propertyTypes = GetPropertyTypes(dto, memberType, standardPropertyTypes); + + //By Convention we add 9 stnd PropertyTypes - This is only here to support loading of types that didn't have these conventions before. + foreach (var standardPropertyType in standardPropertyTypes) + { + if (dto.PropertyTypes.Any(x => x.Alias.Equals(standardPropertyType.Key))) continue; + + // beware! + // means that we can return a memberType "from database" that has some property types + // that do *not* come from the database and therefore are incomplete eg have no key, + // no id, no dataTypeDefinitionId - ouch! - better notify caller of the situation + needsSaving = true; + + //Add the standard PropertyType to the current list + propertyTypes.Add(standardPropertyType.Value); + + //Internal dictionary for adding "MemberCanEdit", "VisibleOnProfile", "IsSensitive" properties to each PropertyType + memberType.MemberTypePropertyTypes.Add(standardPropertyType.Key, + new MemberTypePropertyProfileAccess(false, false, false)); + } + memberType.NoGroupPropertyTypes = propertyTypes; + + return memberType; + } + finally + { + memberType.EnableChangeTracking(); + } + } + + private static PropertyGroupCollection GetPropertyTypeGroupCollection(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary standardProps) + { + // see PropertyGroupFactory, repeating code here... + + var propertyGroups = new PropertyGroupCollection(); + foreach (var groupDto in dto.PropertyTypeGroups.Where(x => x.Id.HasValue)) + { + var group = new PropertyGroup(MemberType.IsPublishingConst); + + // if the group is defined on the current member type, + // assign its identifier, else it will be zero + if (groupDto.ContentTypeNodeId == memberType.Id) + { + // note: no idea why Id is nullable here, but better check + if (groupDto.Id.HasValue == false) + throw new Exception("GroupDto.Id has no value."); + group.Id = groupDto.Id.Value; + } + + group.Key = groupDto.UniqueId; + group.Name = groupDto.Text; + group.SortOrder = groupDto.SortOrder; + group.PropertyTypes = new PropertyTypeCollection(MemberType.IsPublishingConst); + + //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded + var localGroupDto = groupDto; + var typeDtos = dto.PropertyTypes.Where(x => x.Id.HasValue && x.Id > 0 && x.PropertyTypeGroupId.HasValue && x.PropertyTypeGroupId.Value == localGroupDto.Id.Value); + foreach (var typeDto in typeDtos) + { + //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType + memberType.MemberTypePropertyTypes.Add(typeDto.Alias, + new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive)); + + var tempGroupDto = groupDto; + + //ensures that any built-in membership properties have their correct dbtype assigned no matter + //what the underlying data type is + var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty( + typeDto.Alias, + typeDto.DbType.EnumParse(true), + standardProps); + + var propertyType = new PropertyType( + typeDto.PropertyEditorAlias, + propDbType.Result, + //This flag tells the property type that it has an explicit dbtype and that it cannot be changed + // which is what we want for the built-in properties. + propDbType.Success, + typeDto.Alias) + { + DataTypeId = typeDto.DataTypeId, + Description = typeDto.Description, + Id = typeDto.Id.Value, + Name = typeDto.Name, + Mandatory = typeDto.Mandatory, + SortOrder = typeDto.SortOrder, + ValidationRegExp = typeDto.ValidationRegExp, + PropertyGroupId = new Lazy(() => tempGroupDto.Id.Value), + CreateDate = memberType.CreateDate, + UpdateDate = memberType.UpdateDate, + Key = typeDto.UniqueId + }; + + // reset dirty initial properties (U4-1946) + propertyType.ResetDirtyProperties(false); + group.PropertyTypes.Add(propertyType); + } + + // reset dirty initial properties (U4-1946) + group.ResetDirtyProperties(false); + propertyGroups.Add(group); + } + + return propertyGroups; + } + + private static List GetPropertyTypes(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary standardProps) + { + //Find PropertyTypes that does not belong to a PropertyTypeGroup + var propertyTypes = new List(); + foreach (var typeDto in dto.PropertyTypes.Where(x => (x.PropertyTypeGroupId.HasValue == false || x.PropertyTypeGroupId.Value == 0) && x.Id.HasValue)) + { + //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType + memberType.MemberTypePropertyTypes.Add(typeDto.Alias, + new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive)); + + //ensures that any built-in membership properties have their correct dbtype assigned no matter + //what the underlying data type is + var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty( + typeDto.Alias, + typeDto.DbType.EnumParse(true), + standardProps); + + var propertyType = new PropertyType( + typeDto.PropertyEditorAlias, + propDbType.Result, + //This flag tells the property type that it has an explicit dbtype and that it cannot be changed + // which is what we want for the built-in properties. + propDbType.Success, + typeDto.Alias) + { + DataTypeId = typeDto.DataTypeId, + Description = typeDto.Description, + Id = typeDto.Id.Value, + Mandatory = typeDto.Mandatory, + Name = typeDto.Name, + SortOrder = typeDto.SortOrder, + ValidationRegExp = typeDto.ValidationRegExp, + PropertyGroupId = null, + CreateDate = dto.CreateDate, + UpdateDate = dto.CreateDate, + Key = typeDto.UniqueId + }; + + propertyTypes.Add(propertyType); + } + return propertyTypes; + } + + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/ModelFactoryConfiguration.cs b/src/Umbraco.Core/Persistence/Factories/ModelFactoryConfiguration.cs deleted file mode 100644 index 0a7372087d..0000000000 --- a/src/Umbraco.Core/Persistence/Factories/ModelFactoryConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AutoMapper; - -// fixme what is this?! -namespace Umbraco.Core.Persistence.Factories -{ - - ////TODO: Implement AutoMapper for the other factories! - - ///// - ///// This configures all of the AutoMapper supported mapping factories - ///// - //internal class ModelFactoryConfiguration : MapperConfiguration - //{ - // public override void ConfigureMappings(IConfiguration config) - // { - - // UserSectionFactory.ConfigureMappings(config); - // } - //} -} diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs index 59bed3cede..c134748047 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs @@ -1,162 +1,148 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class PropertyGroupFactory - { - private readonly int _contentTypeId; - private readonly DateTime _createDate; - private readonly DateTime _updateDate; - //a callback to create a property type which can be injected via a contructor - private readonly Func _propertyTypeCtor; - - public PropertyGroupFactory(int contentTypeId) - { - _contentTypeId = contentTypeId; - _propertyTypeCtor = (propertyEditorAlias, dbType, alias) => new PropertyType(propertyEditorAlias, dbType); - } - - public PropertyGroupFactory(int contentTypeId, DateTime createDate, DateTime updateDate, Func propertyTypeCtor) - { - _contentTypeId = contentTypeId; - _createDate = createDate; - _updateDate = updateDate; - _propertyTypeCtor = propertyTypeCtor; - } - - #region Implementation of IEntityFactory,IEnumerable> - - public IEnumerable BuildEntity(IEnumerable groupDtos, bool isPublishing) - { - // groupDtos contains all the groups, those that are defined on the current - // content type, and those that are inherited from composition content types - var propertyGroups = new PropertyGroupCollection(); - foreach (var groupDto in groupDtos) - { - var group = new PropertyGroup(isPublishing); - - try - { - group.DisableChangeTracking(); - - // if the group is defined on the current content type, - // assign its identifier, else it will be zero - if (groupDto.ContentTypeNodeId == _contentTypeId) - group.Id = groupDto.Id; - - group.Name = groupDto.Text; - group.SortOrder = groupDto.SortOrder; - group.PropertyTypes = new PropertyTypeCollection(isPublishing); - group.Key = groupDto.UniqueId; - - //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded - var typeDtos = groupDto.PropertyTypeDtos.Where(x => x.Id > 0); - foreach (var typeDto in typeDtos) - { - var tempGroupDto = groupDto; - var propertyType = _propertyTypeCtor(typeDto.DataTypeDto.EditorAlias, - typeDto.DataTypeDto.DbType.EnumParse(true), - typeDto.Alias); - - try - { - propertyType.DisableChangeTracking(); - - propertyType.Alias = typeDto.Alias; - propertyType.DataTypeId = typeDto.DataTypeId; - propertyType.Description = typeDto.Description; - propertyType.Id = typeDto.Id; - propertyType.Key = typeDto.UniqueId; - propertyType.Name = typeDto.Name; - propertyType.Mandatory = typeDto.Mandatory; - propertyType.SortOrder = typeDto.SortOrder; - propertyType.ValidationRegExp = typeDto.ValidationRegExp; - propertyType.PropertyGroupId = new Lazy(() => tempGroupDto.Id); - propertyType.CreateDate = _createDate; - propertyType.UpdateDate = _updateDate; - propertyType.Variations = (ContentVariation) typeDto.Variations; - - // reset dirty initial properties (U4-1946) - propertyType.ResetDirtyProperties(false); - group.PropertyTypes.Add(propertyType); - } - finally - { - propertyType.EnableChangeTracking(); - } - } - - // reset dirty initial properties (U4-1946) - group.ResetDirtyProperties(false); - propertyGroups.Add(group); - } - finally - { - group.EnableChangeTracking(); - } - } - - return propertyGroups; - } - - public IEnumerable BuildDto(IEnumerable entity) - { - return entity.Select(BuildGroupDto).ToList(); - } - - #endregion - - internal PropertyTypeGroupDto BuildGroupDto(PropertyGroup propertyGroup) - { - var dto = new PropertyTypeGroupDto - { - ContentTypeNodeId = _contentTypeId, - SortOrder = propertyGroup.SortOrder, - Text = propertyGroup.Name, - UniqueId = propertyGroup.Key - }; - - if (propertyGroup.HasIdentity) - dto.Id = propertyGroup.Id; - - dto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType)).ToList(); - - return dto; - } - - internal PropertyTypeDto BuildPropertyTypeDto(int tabId, PropertyType propertyType) - { - var propertyTypeDto = new PropertyTypeDto - { - Alias = propertyType.Alias, - ContentTypeId = _contentTypeId, - DataTypeId = propertyType.DataTypeId, - Description = propertyType.Description, - Mandatory = propertyType.Mandatory, - Name = propertyType.Name, - SortOrder = propertyType.SortOrder, - ValidationRegExp = propertyType.ValidationRegExp, - UniqueId = propertyType.Key, - Variations = (byte) propertyType.Variations - }; - - if (tabId != default) - { - propertyTypeDto.PropertyTypeGroupId = tabId; - } - else - { - propertyTypeDto.PropertyTypeGroupId = null; - } - - if (propertyType.HasIdentity) - propertyTypeDto.Id = propertyType.Id; - - return propertyTypeDto; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class PropertyGroupFactory + { + + #region Implementation of IEntityFactory,IEnumerable> + + public static IEnumerable BuildEntity(IEnumerable groupDtos, + bool isPublishing, + int contentTypeId, + DateTime createDate, + DateTime updateDate, + Func propertyTypeCtor) + { + // groupDtos contains all the groups, those that are defined on the current + // content type, and those that are inherited from composition content types + var propertyGroups = new PropertyGroupCollection(); + foreach (var groupDto in groupDtos) + { + var group = new PropertyGroup(isPublishing); + + try + { + group.DisableChangeTracking(); + + // if the group is defined on the current content type, + // assign its identifier, else it will be zero + if (groupDto.ContentTypeNodeId == contentTypeId) + group.Id = groupDto.Id; + + group.Name = groupDto.Text; + group.SortOrder = groupDto.SortOrder; + group.PropertyTypes = new PropertyTypeCollection(isPublishing); + group.Key = groupDto.UniqueId; + + //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded + var typeDtos = groupDto.PropertyTypeDtos.Where(x => x.Id > 0); + foreach (var typeDto in typeDtos) + { + var tempGroupDto = groupDto; + var propertyType = propertyTypeCtor(typeDto.DataTypeDto.EditorAlias, + typeDto.DataTypeDto.DbType.EnumParse(true), + typeDto.Alias); + + try + { + propertyType.DisableChangeTracking(); + + propertyType.Alias = typeDto.Alias; + propertyType.DataTypeId = typeDto.DataTypeId; + propertyType.Description = typeDto.Description; + propertyType.Id = typeDto.Id; + propertyType.Key = typeDto.UniqueId; + propertyType.Name = typeDto.Name; + propertyType.Mandatory = typeDto.Mandatory; + propertyType.SortOrder = typeDto.SortOrder; + propertyType.ValidationRegExp = typeDto.ValidationRegExp; + propertyType.PropertyGroupId = new Lazy(() => tempGroupDto.Id); + propertyType.CreateDate = createDate; + propertyType.UpdateDate = updateDate; + propertyType.Variations = (ContentVariation)typeDto.Variations; + + // reset dirty initial properties (U4-1946) + propertyType.ResetDirtyProperties(false); + group.PropertyTypes.Add(propertyType); + } + finally + { + propertyType.EnableChangeTracking(); + } + } + + // reset dirty initial properties (U4-1946) + group.ResetDirtyProperties(false); + propertyGroups.Add(group); + } + finally + { + group.EnableChangeTracking(); + } + } + + return propertyGroups; + } + + public static IEnumerable BuildDto(IEnumerable entity) + { + return entity.Select(BuildGroupDto).ToList(); + } + + #endregion + + internal static PropertyTypeGroupDto BuildGroupDto(PropertyGroup propertyGroup, int contentTypeId) + { + var dto = new PropertyTypeGroupDto + { + ContentTypeNodeId = contentTypeId, + SortOrder = propertyGroup.SortOrder, + Text = propertyGroup.Name, + UniqueId = propertyGroup.Key + }; + + if (propertyGroup.HasIdentity) + dto.Id = propertyGroup.Id; + + dto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType, contentTypeId)).ToList(); + + return dto; + } + + internal static PropertyTypeDto BuildPropertyTypeDto(int tabId, PropertyType propertyType, int contentTypeId) + { + var propertyTypeDto = new PropertyTypeDto + { + Alias = propertyType.Alias, + ContentTypeId = contentTypeId, + DataTypeId = propertyType.DataTypeId, + Description = propertyType.Description, + Mandatory = propertyType.Mandatory, + Name = propertyType.Name, + SortOrder = propertyType.SortOrder, + ValidationRegExp = propertyType.ValidationRegExp, + UniqueId = propertyType.Key, + Variations = (byte)propertyType.Variations + }; + + if (tabId != default) + { + propertyTypeDto.PropertyTypeGroupId = tabId; + } + else + { + propertyTypeDto.PropertyTypeGroupId = null; + } + + if (propertyType.HasIdentity) + propertyTypeDto.Id = propertyType.Id; + + return propertyTypeDto; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/PublicAccessEntryFactory.cs b/src/Umbraco.Core/Persistence/Factories/PublicAccessEntryFactory.cs index 90ce4f68bb..2a469e4624 100644 --- a/src/Umbraco.Core/Persistence/Factories/PublicAccessEntryFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PublicAccessEntryFactory.cs @@ -1,13 +1,12 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Factories { - internal class PublicAccessEntryFactory + internal static class PublicAccessEntryFactory { - public PublicAccessEntry BuildEntity(AccessDto dto) + public static PublicAccessEntry BuildEntity(AccessDto dto) { var entity = new PublicAccessEntry(dto.Id, dto.NodeId, dto.LoginNodeId, dto.NoAccessNodeId, dto.Rules.Select(x => new PublicAccessRule(x.Id, x.AccessId) @@ -27,7 +26,7 @@ namespace Umbraco.Core.Persistence.Factories return entity; } - public AccessDto BuildDto(PublicAccessEntry entity) + public static AccessDto BuildDto(PublicAccessEntry entity) { var dto = new AccessDto { diff --git a/src/Umbraco.Core/Persistence/Factories/RelationTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/RelationTypeFactory.cs index 6b35452bfa..ca6928a0a1 100644 --- a/src/Umbraco.Core/Persistence/Factories/RelationTypeFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/RelationTypeFactory.cs @@ -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 - - 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 + + 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 + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/ServerRegistrationFactory.cs b/src/Umbraco.Core/Persistence/Factories/ServerRegistrationFactory.cs index 5b0a42ad7b..c49c3968ed 100644 --- a/src/Umbraco.Core/Persistence/Factories/ServerRegistrationFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/ServerRegistrationFactory.cs @@ -1,34 +1,34 @@ -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class ServerRegistrationFactory - { - public ServerRegistration BuildEntity(ServerRegistrationDto dto) - { - var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster); - // reset dirty initial properties (U4-1946) - model.ResetDirtyProperties(false); - return model; - } - - public ServerRegistrationDto BuildDto(IServerRegistration entity) - { - var dto = new ServerRegistrationDto - { - ServerAddress = entity.ServerAddress, - DateRegistered = entity.CreateDate, - IsActive = entity.IsActive, - IsMaster = ((ServerRegistration) entity).IsMaster, - DateAccessed = entity.UpdateDate, - ServerIdentity = entity.ServerIdentity - }; - - if (entity.HasIdentity) - dto.Id = entity.Id; - - return dto; - } - } -} +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class ServerRegistrationFactory + { + public static ServerRegistration BuildEntity(ServerRegistrationDto dto) + { + var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster); + // reset dirty initial properties (U4-1946) + model.ResetDirtyProperties(false); + return model; + } + + public static ServerRegistrationDto BuildDto(IServerRegistration entity) + { + var dto = new ServerRegistrationDto + { + ServerAddress = entity.ServerAddress, + DateRegistered = entity.CreateDate, + IsActive = entity.IsActive, + IsMaster = ((ServerRegistration) entity).IsMaster, + DateAccessed = entity.UpdateDate, + ServerIdentity = entity.ServerIdentity + }; + + if (entity.HasIdentity) + dto.Id = entity.Id; + + return dto; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs b/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs index 98ab898cd4..49bcbd4262 100644 --- a/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/TaskFactory.cs @@ -6,9 +6,9 @@ namespace Umbraco.Core.Persistence.Factories /// /// Creates the model mappings for Tasks /// - internal class TaskFactory + internal static class TaskFactory { - public Task BuildEntity(TaskDto dto) + public static Task BuildEntity(TaskDto dto) { var entity = new Task(new TaskType(dto.TaskTypeDto.Alias) { Id = dto.TaskTypeDto.Id }); @@ -34,7 +34,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public TaskDto BuildDto(Task entity) + public static TaskDto BuildDto(Task entity) { var dto = new TaskDto { diff --git a/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs index f4851c192f..01a25ff852 100644 --- a/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/TaskTypeFactory.cs @@ -3,9 +3,9 @@ using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Factories { - internal class TaskTypeFactory + internal static class TaskTypeFactory { - public TaskType BuildEntity(TaskTypeDto dto) + public static TaskType BuildEntity(TaskTypeDto dto) { var entity = new TaskType(dto.Alias) {Id = dto.Id}; // reset dirty initial properties (U4-1946) @@ -13,7 +13,7 @@ namespace Umbraco.Core.Persistence.Factories return entity; } - public TaskTypeDto BuildDto(TaskType entity) + public static TaskTypeDto BuildDto(TaskType entity) { var dto = new TaskTypeDto { diff --git a/src/Umbraco.Core/Persistence/Factories/TemplateFactory.cs b/src/Umbraco.Core/Persistence/Factories/TemplateFactory.cs index a5be4d05bc..b2b5be872e 100644 --- a/src/Umbraco.Core/Persistence/Factories/TemplateFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/TemplateFactory.cs @@ -1,107 +1,86 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class TemplateFactory - { - private readonly int _primaryKey; - private readonly Guid _nodeObjectTypeId; - - public TemplateFactory() - { - - } - - public TemplateFactory(Guid nodeObjectTypeId) - { - _nodeObjectTypeId = nodeObjectTypeId; - } - - public TemplateFactory(int primaryKey, Guid nodeObjectTypeId) - { - _primaryKey = primaryKey; - _nodeObjectTypeId = nodeObjectTypeId; - } - - #region Implementation of IEntityFactory - - public Template BuildEntity(TemplateDto dto, IEnumerable childDefinitions, Func getFileContent) - { - var template = new Template(dto.NodeDto.Text, dto.Alias, getFileContent); - - try - { - template.DisableChangeTracking(); - - template.CreateDate = dto.NodeDto.CreateDate; - template.Id = dto.NodeId; - template.Key = dto.NodeDto.UniqueId; - template.Path = dto.NodeDto.Path; - - template.IsMasterTemplate = childDefinitions.Any(x => x.ParentId == dto.NodeId); - - if (dto.NodeDto.ParentId > 0) - template.MasterTemplateId = new Lazy(() => dto.NodeDto.ParentId); - - // reset dirty initial properties (U4-1946) - template.ResetDirtyProperties(false); - return template; - } - finally - { - template.EnableChangeTracking(); - } - } - - public TemplateDto BuildDto(Template entity) - { - var dto = new TemplateDto - { - Alias = entity.Alias, - Design = entity.Content ?? string.Empty, - NodeDto = BuildNodeDto(entity) - }; - - if (entity.MasterTemplateId != null && entity.MasterTemplateId.Value > 0) - { - dto.NodeDto.ParentId = entity.MasterTemplateId.Value; - } - - if (entity.HasIdentity) - { - dto.NodeId = entity.Id; - dto.PrimaryKey = _primaryKey; - } - - return dto; - } - - #endregion - - private NodeDto BuildNodeDto(Template entity) - { - var nodeDto = new NodeDto - { - CreateDate = entity.CreateDate, - NodeId = entity.Id, - Level = 1, - NodeObjectType = _nodeObjectTypeId, - ParentId = entity.MasterTemplateId.Value, - Path = entity.Path, - Text = entity.Name, - Trashed = false, - UniqueId = entity.Key - }; - - return nodeDto; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Entities; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class TemplateFactory + { + + #region Implementation of IEntityFactory + + public static Template BuildEntity(TemplateDto dto, IEnumerable childDefinitions, Func getFileContent) + { + var template = new Template(dto.NodeDto.Text, dto.Alias, getFileContent); + + try + { + template.DisableChangeTracking(); + + template.CreateDate = dto.NodeDto.CreateDate; + template.Id = dto.NodeId; + template.Key = dto.NodeDto.UniqueId; + template.Path = dto.NodeDto.Path; + + template.IsMasterTemplate = childDefinitions.Any(x => x.ParentId == dto.NodeId); + + if (dto.NodeDto.ParentId > 0) + template.MasterTemplateId = new Lazy(() => dto.NodeDto.ParentId); + + // reset dirty initial properties (U4-1946) + template.ResetDirtyProperties(false); + return template; + } + finally + { + template.EnableChangeTracking(); + } + } + + public static TemplateDto BuildDto(Template entity, Guid? nodeObjectTypeId,int primaryKey) + { + var dto = new TemplateDto + { + Alias = entity.Alias, + Design = entity.Content ?? string.Empty, + NodeDto = BuildNodeDto(entity, nodeObjectTypeId) + }; + + if (entity.MasterTemplateId != null && entity.MasterTemplateId.Value > 0) + { + dto.NodeDto.ParentId = entity.MasterTemplateId.Value; + } + + if (entity.HasIdentity) + { + dto.NodeId = entity.Id; + dto.PrimaryKey = primaryKey; + } + + return dto; + } + + #endregion + + private static NodeDto BuildNodeDto(Template entity,Guid? nodeObjectTypeId) + { + var nodeDto = new NodeDto + { + CreateDate = entity.CreateDate, + NodeId = entity.Id, + Level = 1, + NodeObjectType = nodeObjectTypeId, + ParentId = entity.MasterTemplateId.Value, + Path = entity.Path, + Text = entity.Name, + Trashed = false, + UniqueId = entity.Key + }; + + return nodeDto; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs index 394477cb51..dae70d502f 100644 --- a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs @@ -1,104 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal static class UserFactory - { - public static IUser BuildEntity(UserDto dto) - { - var guidId = dto.Id.ToGuid(); - - var user = new User(dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password, - dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray(), - dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(), - dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray()); - - try - { - user.DisableChangeTracking(); - - user.Key = guidId; - user.IsLockedOut = dto.NoConsole; - user.IsApproved = dto.Disabled == false; - user.Language = dto.UserLanguage; - user.SecurityStamp = dto.SecurityStampToken; - user.FailedPasswordAttempts = dto.FailedLoginAttempts ?? 0; - user.LastLockoutDate = dto.LastLockoutDate ?? DateTime.MinValue; - user.LastLoginDate = dto.LastLoginDate ?? DateTime.MinValue; - user.LastPasswordChangeDate = dto.LastPasswordChangeDate ?? DateTime.MinValue; - user.CreateDate = dto.CreateDate; - user.UpdateDate = dto.UpdateDate; - user.Avatar = dto.Avatar; - user.EmailConfirmedDate = dto.EmailConfirmedDate; - user.InvitedDate = dto.InvitedDate; - user.TourData = dto.TourData; - - // reset dirty initial properties (U4-1946) - user.ResetDirtyProperties(false); - - return user; - } - finally - { - user.EnableChangeTracking(); - } - } - - public static UserDto BuildDto(IUser entity) - { - var dto = new UserDto - { - Disabled = entity.IsApproved == false, - Email = entity.Email, - Login = entity.Username, - NoConsole = entity.IsLockedOut, - Password = entity.RawPasswordValue, - UserLanguage = entity.Language, - UserName = entity.Name, - SecurityStampToken = entity.SecurityStamp, - FailedLoginAttempts = entity.FailedPasswordAttempts, - LastLockoutDate = entity.LastLockoutDate == DateTime.MinValue ? (DateTime?)null : entity.LastLockoutDate, - LastLoginDate = entity.LastLoginDate == DateTime.MinValue ? (DateTime?)null : entity.LastLoginDate, - LastPasswordChangeDate = entity.LastPasswordChangeDate == DateTime.MinValue ? (DateTime?)null : entity.LastPasswordChangeDate, - CreateDate = entity.CreateDate, - UpdateDate = entity.UpdateDate, - Avatar = entity.Avatar, - EmailConfirmedDate = entity.EmailConfirmedDate, +using System; +using System.Linq; +using Umbraco.Core.Models.Membership; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal static class UserFactory + { + public static IUser BuildEntity(UserDto dto) + { + var guidId = dto.Id.ToGuid(); + + var user = new User(dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password, + dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray(), + dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(), + dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray()); + + try + { + user.DisableChangeTracking(); + + user.Key = guidId; + user.IsLockedOut = dto.NoConsole; + user.IsApproved = dto.Disabled == false; + user.Language = dto.UserLanguage; + user.SecurityStamp = dto.SecurityStampToken; + user.FailedPasswordAttempts = dto.FailedLoginAttempts ?? 0; + user.LastLockoutDate = dto.LastLockoutDate ?? DateTime.MinValue; + user.LastLoginDate = dto.LastLoginDate ?? DateTime.MinValue; + user.LastPasswordChangeDate = dto.LastPasswordChangeDate ?? DateTime.MinValue; + user.CreateDate = dto.CreateDate; + user.UpdateDate = dto.UpdateDate; + user.Avatar = dto.Avatar; + user.EmailConfirmedDate = dto.EmailConfirmedDate; + user.InvitedDate = dto.InvitedDate; + user.TourData = dto.TourData; + + // reset dirty initial properties (U4-1946) + user.ResetDirtyProperties(false); + + return user; + } + finally + { + user.EnableChangeTracking(); + } + } + + public static UserDto BuildDto(IUser entity) + { + var dto = new UserDto + { + Disabled = entity.IsApproved == false, + Email = entity.Email, + Login = entity.Username, + NoConsole = entity.IsLockedOut, + Password = entity.RawPasswordValue, + UserLanguage = entity.Language, + UserName = entity.Name, + SecurityStampToken = entity.SecurityStamp, + FailedLoginAttempts = entity.FailedPasswordAttempts, + LastLockoutDate = entity.LastLockoutDate == DateTime.MinValue ? (DateTime?)null : entity.LastLockoutDate, + LastLoginDate = entity.LastLoginDate == DateTime.MinValue ? (DateTime?)null : entity.LastLoginDate, + LastPasswordChangeDate = entity.LastPasswordChangeDate == DateTime.MinValue ? (DateTime?)null : entity.LastPasswordChangeDate, + CreateDate = entity.CreateDate, + UpdateDate = entity.UpdateDate, + Avatar = entity.Avatar, + EmailConfirmedDate = entity.EmailConfirmedDate, InvitedDate = entity.InvitedDate, - TourData = entity.TourData - }; - - foreach (var startNodeId in entity.StartContentIds) - { - dto.UserStartNodeDtos.Add(new UserStartNodeDto - { - StartNode = startNodeId, - StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Content, - UserId = entity.Id - }); - } - - foreach (var startNodeId in entity.StartMediaIds) - { - dto.UserStartNodeDtos.Add(new UserStartNodeDto - { - StartNode = startNodeId, - StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Media, - UserId = entity.Id - }); - } - - if (entity.HasIdentity) - { - dto.Id = entity.Id.SafeCast(); - } - - return dto; - } - } -} + TourData = entity.TourData + }; + + foreach (var startNodeId in entity.StartContentIds) + { + dto.UserStartNodeDtos.Add(new UserStartNodeDto + { + StartNode = startNodeId, + StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Content, + UserId = entity.Id + }); + } + + foreach (var startNodeId in entity.StartMediaIds) + { + dto.UserStartNodeDtos.Add(new UserStartNodeDto + { + StartNode = startNodeId, + StartNodeType = (int)UserStartNodeDto.StartNodeTypeValue.Media, + UserId = entity.Id + }); + } + + if (entity.HasIdentity) + { + dto.Id = entity.Id.SafeCast(); + } + + return dto; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index 051cdebd2b..9a077a320e 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -119,8 +119,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected void PersistNewBaseContentType(IContentTypeComposition entity) { - var factory = new ContentTypeFactory(); - var dto = factory.BuildContentTypeDto(entity); + + var dto = ContentTypeFactory.BuildContentTypeDto(entity); //Cannot add a duplicate content type type var exists = Database.ExecuteScalar(@"SELECT COUNT(*) FROM cmsContentType @@ -191,13 +191,12 @@ AND umbracoNode.nodeObjectType = @objectType", SortOrder = allowedContentType.SortOrder }); } - - var propertyFactory = new PropertyGroupFactory(nodeDto.NodeId); - + + //Insert Tabs foreach (var propertyGroup in entity.PropertyGroups) { - var tabDto = propertyFactory.BuildGroupDto(propertyGroup); + var tabDto = PropertyGroupFactory.BuildGroupDto(propertyGroup, nodeDto.NodeId); var primaryKey = Convert.ToInt32(Database.Insert(tabDto)); propertyGroup.Id = primaryKey;//Set Id on PropertyGroup @@ -222,7 +221,7 @@ AND umbracoNode.nodeObjectType = @objectType", { AssignDataTypeFromPropertyEditor(propertyType); } - var propertyTypeDto = propertyFactory.BuildPropertyTypeDto(tabId, propertyType); + var propertyTypeDto = PropertyGroupFactory.BuildPropertyTypeDto(tabId, propertyType, nodeDto.NodeId); int typePrimaryKey = Convert.ToInt32(Database.Insert(propertyTypeDto)); propertyType.Id = typePrimaryKey; //Set Id on new PropertyType @@ -235,8 +234,8 @@ AND umbracoNode.nodeObjectType = @objectType", protected void PersistUpdatedBaseContentType(IContentTypeComposition entity) { - var factory = new ContentTypeFactory(); - var dto = factory.BuildContentTypeDto(entity); + + var dto = ContentTypeFactory.BuildContentTypeDto(entity); // ensure the alias is not used already var exists = Database.ExecuteScalar(@"SELECT COUNT(*) FROM cmsContentType @@ -384,13 +383,12 @@ AND umbracoNode.id <> @id", Database.Delete("WHERE id IN (@ids)", new { ids = groupsToDelete }); } } - var propertyGroupFactory = new PropertyGroupFactory(entity.Id); // insert or update groups, assign properties foreach (var propertyGroup in entity.PropertyGroups) { // insert or update group - var groupDto = propertyGroupFactory.BuildGroupDto(propertyGroup); + var groupDto = PropertyGroupFactory.BuildGroupDto(propertyGroup,entity.Id); var groupId = propertyGroup.HasIdentity ? Database.Update(groupDto) : Convert.ToInt32(Database.Insert(groupDto)); @@ -419,7 +417,7 @@ AND umbracoNode.id <> @id", ValidateAlias(propertyType); // insert or update property - var propertyTypeDto = propertyGroupFactory.BuildPropertyTypeDto(groupId, propertyType); + var propertyTypeDto = PropertyGroupFactory.BuildPropertyTypeDto(groupId, propertyType, entity.Id); var typeId = propertyType.HasIdentity ? Database.Update(propertyTypeDto) : Convert.ToInt32(Database.Insert(propertyTypeDto)); @@ -480,8 +478,8 @@ AND umbracoNode.id <> @id", var dtos = Database .Fetch(sql); - var propertyGroupFactory = new PropertyGroupFactory(id, createDate, updateDate, CreatePropertyType); - var propertyGroups = propertyGroupFactory.BuildEntity(dtos, IsPublishing); + var propertyGroups = PropertyGroupFactory.BuildEntity(dtos, IsPublishing, id, createDate, updateDate,CreatePropertyType); + return new PropertyGroupCollection(propertyGroups); } @@ -870,10 +868,8 @@ AND umbracoNode.id <> @id", } }; - //now create the content type object - - var factory = new ContentTypeFactory(); - var mediaType = factory.BuildMediaTypeEntity(contentTypeDto); + //now create the content type object; + var mediaType = ContentTypeFactory.BuildMediaTypeEntity(contentTypeDto); //map the allowed content types mediaType.AllowedContentTypes = currAllowedContentTypes; @@ -1052,9 +1048,7 @@ AND umbracoNode.id <> @id", }; //now create the content type object - - var factory = new ContentTypeFactory(); - var contentType = factory.BuildContentTypeEntity(dtDto.ContentTypeDto); + var contentType = ContentTypeFactory.BuildContentTypeEntity(dtDto.ContentTypeDto); // NOTE // that was done by the factory but makes little sense, moved here, so diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs index 75bcb5e0c0..8f5ad70c32 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs @@ -130,17 +130,15 @@ namespace Umbraco.Core.Persistence.Repositories.Implement foreach (var translation in dictionaryItem.Translations) translation.Value = translation.Value.ToValidXmlString(); - - var factory = new DictionaryItemFactory(); - var dto = factory.BuildDto(dictionaryItem); + + var dto = DictionaryItemFactory.BuildDto(dictionaryItem); var id = Convert.ToInt32(Database.Insert(dto)); dictionaryItem.Id = id; - var translationFactory = new DictionaryTranslationFactory(dictionaryItem.Key); foreach (var translation in dictionaryItem.Translations) { - var textDto = translationFactory.BuildDto(translation); + var textDto = DictionaryTranslationFactory.BuildDto(translation, dictionaryItem.Key); translation.Id = Convert.ToInt32(Database.Insert(textDto)); translation.Key = dictionaryItem.Key; } @@ -154,16 +152,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement foreach (var translation in entity.Translations) translation.Value = translation.Value.ToValidXmlString(); - - var factory = new DictionaryItemFactory(); - var dto = factory.BuildDto(entity); + + var dto = DictionaryItemFactory.BuildDto(entity); Database.Update(dto); - var translationFactory = new DictionaryTranslationFactory(entity.Key); foreach (var translation in entity.Translations) { - var textDto = translationFactory.BuildDto(translation); + var textDto = DictionaryTranslationFactory.BuildDto(translation, entity.Key); if (translation.HasIdentity) { Database.Update(textDto); @@ -216,13 +212,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected IDictionaryItem ConvertFromDto(DictionaryDto dto) { - var factory = new DictionaryItemFactory(); - var entity = factory.BuildEntity(dto); + var entity = DictionaryItemFactory.BuildEntity(dto); - var f = new DictionaryTranslationFactory(dto.UniqueId); entity.Translations = dto.LanguageTextDtos.EmptyNull() .Where(x => x.LanguageId > 0) - .Select(x => f.BuildEntity(x)) + .Select(x => DictionaryTranslationFactory.BuildEntity(x, dto.UniqueId)) .ToList(); return entity; 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/LanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs index f8edcf6811..db2e1124a2 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs @@ -139,8 +139,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement IsolatedCache.ClearAllCache(); } - var factory = new LanguageFactory(); - var dto = factory.BuildDto(entity); +; + var dto = LanguageFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; @@ -163,9 +163,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement //We need to clear the whole cache since all languages will be updated IsolatedCache.ClearAllCache(); } - - var factory = new LanguageFactory(); - var dto = factory.BuildDto(entity); + + var dto = LanguageFactory.BuildDto(entity); Database.Update(dto); @@ -197,8 +196,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected ILanguage ConvertFromDto(LanguageDto dto) { - var factory = new LanguageFactory(); - var entity = factory.BuildEntity(dto); + var entity = LanguageFactory.BuildEntity(dto); return entity; } 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); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs index f29fef1102..2ba2d5a956 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs @@ -19,8 +19,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement : base(scopeAccessor, cache, logger) { } - private readonly MemberGroupFactory _modelFactory = new MemberGroupFactory(); - protected override IMemberGroup PerformGet(int id) { var sql = GetBaseQuery(false); @@ -28,7 +26,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var dto = Database.Fetch(SqlSyntax.SelectTop(sql, 1)).FirstOrDefault(); - return dto == null ? null : _modelFactory.BuildEntity(dto); + return dto == null ? null : MemberGroupFactory.BuildEntity(dto); } protected override IEnumerable PerformGetAll(params int[] ids) @@ -41,7 +39,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (ids.Any()) sql.Where("umbracoNode.id in (@ids)", new { /*ids =*/ ids }); - return Database.Fetch(sql).Select(x => _modelFactory.BuildEntity(x)); + return Database.Fetch(sql).Select(x => MemberGroupFactory.BuildEntity(x)); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -50,7 +48,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate(); - return Database.Fetch(sql).Select(x => _modelFactory.BuildEntity(x)); + return Database.Fetch(sql).Select(x => MemberGroupFactory.BuildEntity(x)); } protected override Sql GetBaseQuery(bool isCount) @@ -95,7 +93,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement //Save to db var group = (MemberGroup)entity; group.AddingEntity(); - var dto = _modelFactory.BuildDto(group); + var dto = MemberGroupFactory.BuildDto(group); var o = Database.IsNew(dto) ? Convert.ToInt32(Database.Insert(dto)) : Database.Update(dto); group.Id = dto.NodeId; //Set Id on entity to ensure an Id is set @@ -109,7 +107,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IMemberGroup entity) { - var dto = _modelFactory.BuildDto(entity); + var dto = MemberGroupFactory.BuildDto(entity); Database.Update(dto); @@ -164,7 +162,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement return Database.Fetch(sql) .DistinctBy(dto => dto.NodeId) - .Select(x => _modelFactory.BuildEntity(x)); + .Select(x => MemberGroupFactory.BuildEntity(x)); } public IEnumerable GetMemberGroupsForMember(string username) @@ -181,7 +179,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement return Database.Fetch(sql) .DistinctBy(dto => dto.NodeId) - .Select(x => _modelFactory.BuildEntity(x)); + .Select(x => MemberGroupFactory.BuildEntity(x)); } public int[] GetMemberIds(string[] usernames) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs index 3208cae41e..023e308ad3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs @@ -212,14 +212,12 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { entity.AddPropertyType(standardPropertyType.Value, Constants.Conventions.Member.StandardPropertiesGroupName); } - - var factory = new ContentTypeFactory(); - + EnsureExplicitDataTypeForBuiltInProperties(entity); PersistNewBaseContentType(entity); //Handles the MemberTypeDto (cmsMemberType table) - var memberTypeDtos = factory.BuildMemberTypeDtos(entity); + var memberTypeDtos = ContentTypeFactory.BuildMemberTypeDtos(entity); foreach (var memberTypeDto in memberTypeDtos) { Database.Insert(memberTypeDto); @@ -247,15 +245,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId }); entity.SortOrder = maxSortOrder + 1; } - - var factory = new ContentTypeFactory(); - + EnsureExplicitDataTypeForBuiltInProperties(entity); PersistUpdatedBaseContentType(entity); // remove and insert - handle cmsMemberType table Database.Delete("WHERE NodeId = @Id", new { Id = entity.Id }); - var memberTypeDtos = factory.BuildMemberTypeDtos(entity); + var memberTypeDtos = ContentTypeFactory.BuildMemberTypeDtos(entity); foreach (var memberTypeDto in memberTypeDtos) { Database.Insert(memberTypeDto); @@ -311,12 +307,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { if (dtos == null || dtos.Any() == false) return Enumerable.Empty(); - - var factory = new MemberTypeReadOnlyFactory(); + return dtos.Select(x => { bool needsSaving; - var memberType = factory.BuildEntity(x, out needsSaving); + var memberType = MemberTypeReadOnlyFactory.BuildEntity(x, out needsSaving); if (needsSaving) PersistUpdatedItem(memberType); return memberType; }).ToList(); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/PublicAccessRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/PublicAccessRepository.cs index 61b094eb78..f49905573d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/PublicAccessRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/PublicAccessRepository.cs @@ -39,10 +39,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } sql.OrderBy(x => x.NodeId); - - var factory = new PublicAccessEntryFactory(); + var dtos = Database.FetchOneToMany(x => x.Rules, sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(PublicAccessEntryFactory.BuildEntity); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -50,10 +49,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var sqlClause = GetBaseQuery(false); var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate(); - - var factory = new PublicAccessEntryFactory(); + var dtos = Database.FetchOneToMany(x => x.Rules, sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(PublicAccessEntryFactory.BuildEntity); } protected override Sql GetBaseQuery(bool isCount) @@ -87,9 +85,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement entity.AddingEntity(); foreach (var rule in entity.Rules) rule.AddingEntity(); - - var factory = new PublicAccessEntryFactory(); - var dto = factory.BuildDto(entity); + + var dto = PublicAccessEntryFactory.BuildDto(entity); Database.Insert(dto); //update the id so HasEntity is correct @@ -118,9 +115,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement else rule.AddingEntity(); } - - var factory = new PublicAccessEntryFactory(); - var dto = factory.BuildDto(entity); + + var dto = PublicAccessEntryFactory.BuildDto(entity); Database.Update(dto); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs index f5b064516f..e4d8396e71 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs @@ -55,8 +55,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement throw new NotImplementedException(); var dtos = Database.Fetch(sql); - var factory = new RelationTypeFactory(); - return dtos.Select(x => DtoToEntity(x, factory)); + + return dtos.Select(x => DtoToEntity(x)); } public IEnumerable GetMany(params Guid[] ids) @@ -75,13 +75,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var sql = translator.Translate(); var dtos = Database.Fetch(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(); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ServerRegistrationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ServerRegistrationRepository.cs index 88051c2134..531df1ba13 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ServerRegistrationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ServerRegistrationRepository.cs @@ -56,9 +56,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override IEnumerable PerformGetAll(params int[] ids) { - var factory = new ServerRegistrationFactory(); return Database.Fetch("WHERE id > 0") - .Select(x => factory.BuildEntity(x)); + .Select(x => ServerRegistrationFactory.BuildEntity(x)); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -100,8 +99,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { ((ServerRegistration)entity).AddingEntity(); - var factory = new ServerRegistrationFactory(); - var dto = factory.BuildDto(entity); + var dto = ServerRegistrationFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; @@ -112,9 +110,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IServerRegistration entity) { ((ServerRegistration)entity).UpdatingEntity(); - - var factory = new ServerRegistrationFactory(); - var dto = factory.BuildDto(entity); + + var dto = ServerRegistrationFactory.BuildDto(entity); Database.Update(dto); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TaskRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TaskRepository.cs index f33a1c852a..656c97a1e9 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TaskRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TaskRepository.cs @@ -29,9 +29,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var taskDto = Database.Fetch(SqlContext.SqlSyntax.SelectTop(sql, 1)).FirstOrDefault(); if (taskDto == null) return null; - - var factory = new TaskFactory(); - var entity = factory.BuildEntity(taskDto); + + var entity = TaskFactory.BuildEntity(taskDto); return entity; } @@ -43,10 +42,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { sql.Where("cmsTask.id IN (@ids)", new { ids = ids }); } - - var factory = new TaskFactory(); + var dtos = Database.Fetch(sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(TaskFactory.BuildEntity); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -55,9 +53,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate(); - var factory = new TaskFactory(); var dtos = Database.Fetch(sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(TaskFactory.BuildEntity); } protected override Sql GetBaseQuery(bool isCount) @@ -107,9 +104,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { entity.TaskType.Id = taskType.Id; } - - var factory = new TaskFactory(); - var dto = factory.BuildDto(entity); + + var dto = TaskFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; @@ -120,9 +116,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(Task entity) { entity.UpdatingEntity(); - - var factory = new TaskFactory(); - var dto = factory.BuildDto(entity); + + var dto = TaskFactory.BuildDto(entity); Database.Update(dto); @@ -138,8 +133,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } var dtos = Database.Fetch(sql); - var factory = new TaskFactory(); - return dtos.Select(factory.BuildEntity); + + return dtos.Select(TaskFactory.BuildEntity); } private Sql GetGetTasksQuery(int? assignedUser = null, int? ownerUser = null, string taskTypeAlias = null, bool includeClosed = false) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TaskTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TaskTypeRepository.cs index abd21002a1..8669e7a9dc 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TaskTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TaskTypeRepository.cs @@ -28,9 +28,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var taskDto = Database.Fetch(SqlContext.SqlSyntax.SelectTop(sql, 1)).FirstOrDefault(); if (taskDto == null) return null; - - var factory = new TaskTypeFactory(); - var entity = factory.BuildEntity(taskDto); + + var entity = TaskTypeFactory.BuildEntity(taskDto); return entity; } @@ -42,10 +41,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { sql.Where("cmsTaskType.id IN (@ids)", new { ids }); } - - var factory = new TaskTypeFactory(); + var dtos = Database.Fetch(sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(TaskTypeFactory.BuildEntity); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -53,10 +51,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var sqlClause = GetBaseQuery(false); var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate(); - - var factory = new TaskTypeFactory(); + var dtos = Database.Fetch(sql); - return dtos.Select(factory.BuildEntity); + return dtos.Select(TaskTypeFactory.BuildEntity); } protected override Sql GetBaseQuery(bool isCount) @@ -93,9 +90,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { throw new InvalidOperationException("A task type already exists with the given alias " + entity.Alias); } - - var factory = new TaskTypeFactory(); - var dto = factory.BuildDto(entity); + + var dto = TaskTypeFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; @@ -106,9 +102,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(TaskType entity) { entity.UpdatingEntity(); - - var factory = new TaskTypeFactory(); - var dto = factory.BuildDto(entity); + + var dto = TaskTypeFactory.BuildDto(entity); Database.Update(dto); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs index 32080c4a12..3f573ff67d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs @@ -152,9 +152,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement //Save to db var template = (Template)entity; template.AddingEntity(); - - var factory = new TemplateFactory(NodeObjectTypeId); - var dto = factory.BuildDto(template); + + var dto = TemplateFactory.BuildDto(template, NodeObjectTypeId, template.Id); //Create the (base) node data - umbracoNode var nodeDto = dto.NodeDto; @@ -226,8 +225,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement //Save updated entity to db template.UpdateDate = DateTime.Now; - var factory = new TemplateFactory(templateDto.PrimaryKey, NodeObjectTypeId); - var dto = factory.BuildDto(template); + ; + var dto = TemplateFactory.BuildDto(template, NodeObjectTypeId, templateDto.PrimaryKey); Database.Update(dto.NodeDto); Database.Update(dto); @@ -355,8 +354,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// private ITemplate MapFromDto(TemplateDto dto, IUmbracoEntity[] axisDefinitions) { - var factory = new TemplateFactory(); - var template = factory.BuildEntity(dto, axisDefinitions, file => GetFileContent((Template) file, false)); + + var template = TemplateFactory.BuildEntity(dto, axisDefinitions, file => GetFileContent((Template) file, false)); if (dto.NodeDto.ParentId > 0) { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9ebeb12b77..6bd78044f8 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1,1524 +1,1523 @@ - - - - - v4.7.2 - false - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} - Library - Umbraco.Core - Umbraco.Core - ..\ - - - - true - full - false - bin\Debug\ - TRACE;DEBUG - prompt - 4 - false - latest - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\Umbraco.Core.xml - false - latest - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Component - - - Component - - - Properties\SolutionInfo.cs - - - - - - - - - - + + + + + v4.7.2 + false + {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} + Library + Umbraco.Core + Umbraco.Core + ..\ + + + + true + full + false + bin\Debug\ + TRACE;DEBUG + prompt + 4 + false + latest + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\Umbraco.Core.xml + false + latest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Component + + + Component + + + Properties\SolutionInfo.cs + + + + + + + + + + \ No newline at end of file