From 6fd185df2df8593155dfa6d04bf74a9391f9f3bd Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 3 Nov 2015 17:54:51 +0100 Subject: [PATCH] Replace evil magic number with constant --- .../Models/Mapping/ContentTypeModelMappingTests.cs | 6 +++--- .../Models/ContentEditing/PropertyGroupBasic.cs | 6 ++++++ .../Models/Mapping/ContentTypeModelMapperExtensions.cs | 6 +++--- .../Models/Mapping/PropertyTypeGroupResolver.cs | 8 ++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index 88dc4e8e89..bea607bb26 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -398,9 +398,9 @@ namespace Umbraco.Tests.Models.Mapping //TODO: Now we need to assert all of the more complicated parts - Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.Id != -666)); - Assert.AreEqual(1, result.Groups.Count(x => x.Id == -666)); - Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.Id != -666)); + Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false)); + Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties)); + Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false)); var allPropertiesMapped = result.Groups.SelectMany(x => x.Properties).ToArray(); var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray(); diff --git a/src/Umbraco.Web/Models/ContentEditing/PropertyGroupBasic.cs b/src/Umbraco.Web/Models/ContentEditing/PropertyGroupBasic.cs index d942c433ce..2a21b3c61e 100644 --- a/src/Umbraco.Web/Models/ContentEditing/PropertyGroupBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/PropertyGroupBasic.cs @@ -13,6 +13,12 @@ namespace Umbraco.Web.Models.ContentEditing Properties = new List(); } + // a special id we use for generic properties + public const int GenericPropertiesGroupId = -666; + + [IgnoreDataMember] + public bool IsGenericProperties { get { return Id == GenericPropertiesGroupId; } } + //Indicate if this tab was inherited [DataMember(Name = "inherited")] public bool Inherited { get; set; } diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapperExtensions.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapperExtensions.cs index cfa12e214f..08e579a823 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapperExtensions.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapperExtensions.cs @@ -130,8 +130,8 @@ namespace Umbraco.Web.Models.Mapping var addedProperties = new List(); - //get all properties from groups that are not generic properties or inhertied (-666 id) - var selfNonGenericGroups = source.Groups.Where(x => x.Inherited == false && x.Id != -666).ToArray(); + //get all properties from groups that are not generic properties or inhertied + var selfNonGenericGroups = source.Groups.Where(x => x.Inherited == false && x.IsGenericProperties == false).ToArray(); foreach (var group in selfNonGenericGroups) { @@ -168,7 +168,7 @@ namespace Umbraco.Web.Models.Mapping } //add generic properties - var genericProperties = source.Groups.FirstOrDefault(x => x.Id == -666); + var genericProperties = source.Groups.FirstOrDefault(x => x.IsGenericProperties); if (genericProperties != null) { foreach (var propertyTypeBasic in genericProperties.Properties.Where(x => x.Inherited == false)) diff --git a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupResolver.cs b/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupResolver.cs index 2802fe2965..5d2d1c3123 100644 --- a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupResolver.cs @@ -91,23 +91,23 @@ namespace Umbraco.Web.Models.Mapping //process generic properties assigned to this content item (without a group) - //NOTE: -666 is just a thing that is checked during mapping the other direction, it's a 'special' id + //NOTE: GenericPropertiesGroupId is just a thing that is checked during mapping the other direction, it's a 'special' id var entityGenericProperties = source.PropertyTypes.Where(x => x.PropertyGroupId == null); - genericProperties.AddRange(MapProperties(entityGenericProperties, source, -666, false)); + genericProperties.AddRange(MapProperties(entityGenericProperties, source, PropertyGroupDisplay.GenericPropertiesGroupId, false)); //process generic properties from compositions (ensures properties are flagged as inherited) var currentGenericPropertyIds = genericProperties.Select(x => x.Id).ToArray(); var compositionGenericProperties = source.CompositionPropertyTypes .Where(x => x.PropertyGroupId == null && currentGenericPropertyIds.Contains(x.Id) == false); - genericProperties.AddRange(MapProperties(compositionGenericProperties, source, -666, true)); + genericProperties.AddRange(MapProperties(compositionGenericProperties, source, PropertyGroupDisplay.GenericPropertiesGroupId, true)); //now add the group if there are any generic props if (genericProperties.Any()) { var genericTab = new PropertyGroupDisplay { - Id = -666, Name = "Generic properties", ParentGroupId = 0, ContentTypeId = source.Id, SortOrder = 999, Inherited = false, Properties = genericProperties + Id = PropertyGroupDisplay.GenericPropertiesGroupId, Name = "Generic properties", ParentGroupId = 0, ContentTypeId = source.Id, SortOrder = 999, Inherited = false, Properties = genericProperties }; groups.Add(0, genericTab); }