Replace evil magic number with constant

This commit is contained in:
Stephan
2015-11-03 17:54:51 +01:00
parent 901d55b472
commit 6fd185df2d
4 changed files with 16 additions and 10 deletions

View File

@@ -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();

View File

@@ -13,6 +13,12 @@ namespace Umbraco.Web.Models.ContentEditing
Properties = new List<TPropertyType>();
}
// 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; }

View File

@@ -130,8 +130,8 @@ namespace Umbraco.Web.Models.Mapping
var addedProperties = new List<string>();
//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))

View File

@@ -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);
}