fixes prop group/prop type mapping for when there is a new property group with new property types assigned
This commit is contained in:
@@ -104,7 +104,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
// Act
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType();
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test", propertyGroupName:"testGroup");
|
||||
repository.AddOrUpdate(contentType);
|
||||
unitOfWork.Commit();
|
||||
|
||||
@@ -113,7 +113,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True);
|
||||
Assert.That(contentType.PropertyTypes.All(x => x.HasIdentity), Is.True);
|
||||
Assert.That(contentType.Path.Contains(","), Is.True);
|
||||
Assert.That(contentType.SortOrder, Is.GreaterThan(0));
|
||||
Assert.That(contentType.SortOrder, Is.GreaterThan(0));
|
||||
|
||||
Assert.That(contentType.PropertyGroups.ElementAt(0).Name == "testGroup", Is.True);
|
||||
var groupId = contentType.PropertyGroups.ElementAt(0).Id;
|
||||
Assert.That(contentType.PropertyTypes.All(x => x.PropertyGroupId.Value == groupId), Is.True);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -127,7 +131,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
using (var repository = CreateRepository(unitOfWork))
|
||||
{
|
||||
// Act
|
||||
var contentType = (IContentType)MockedContentTypes.CreateSimpleContentType();
|
||||
var contentType = (IContentType)MockedContentTypes.CreateSimpleContentType("test", "Test", propertyGroupName: "testGroup");
|
||||
var display = Mapper.Map<ContentTypeDisplay>(contentType);
|
||||
//simulate what would happen in the controller, we'd never map to a 'existing' content type,
|
||||
// we'd map to an new content type when updating.
|
||||
@@ -145,6 +149,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(contentType.PropertyTypes.All(x => x.HasIdentity), Is.True);
|
||||
Assert.That(contentType.Path.Contains(","), Is.True);
|
||||
Assert.That(contentType.SortOrder, Is.GreaterThan(0));
|
||||
|
||||
Assert.That(contentType.PropertyGroups.ElementAt(0).Name == "testGroup", Is.True);
|
||||
var groupId = contentType.PropertyGroups.ElementAt(0).Id;
|
||||
Assert.That(contentType.PropertyTypes.All(x => x.PropertyGroupId.Value == groupId), Is.True);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,7 +131,14 @@ namespace Umbraco.Web.Models.Mapping
|
||||
destination.PropertyTypes = new PropertyTypeCollection();
|
||||
foreach (var propertyTypeDisplay in source.Properties.Where(x => x.Label.IsNullOrWhiteSpace() == false ))
|
||||
{
|
||||
destination.PropertyTypes.Add(Mapper.Map<PropertyType>(propertyTypeDisplay));
|
||||
var propertyType = Mapper.Map<PropertyType>(propertyTypeDisplay);
|
||||
if (source.Id <= 0)
|
||||
{
|
||||
//there is no id assigned which means it's a new group and the property type needs to be assigned to it, so
|
||||
// we need to set the lazy id correctly to the PropertyGroup destination
|
||||
propertyType.PropertyGroupId = new Lazy<int>(() => destination.Id, false);
|
||||
}
|
||||
destination.PropertyTypes.Add(propertyType);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -143,10 +150,13 @@ namespace Umbraco.Web.Models.Mapping
|
||||
if (dataType == null) throw new NullReferenceException("No data type found with id " + propertyTypeDisplay.DataTypeId);
|
||||
return new PropertyType(dataType, propertyTypeDisplay.Alias);
|
||||
})
|
||||
//only map if it is actually set
|
||||
.ForMember(dest => dest.Id, expression => expression.Condition(source => source.Id > 0))
|
||||
.ForMember(dto => dto.CreateDate, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.UpdateDate, expression => expression.Ignore())
|
||||
.ForMember(type => type.PropertyGroupId, expression => expression.MapFrom(display => new Lazy<int>(() => display.GroupId, LazyThreadSafetyMode.None)))
|
||||
//only map if it is actually set, if it's not set, it needs to be handled differently!
|
||||
.ForMember(dest => dest.PropertyGroupId, expression => expression.Condition(source => source.GroupId > 0))
|
||||
.ForMember(type => type.PropertyGroupId, expression => expression.MapFrom(display => new Lazy<int>(() => display.GroupId, false)))
|
||||
.ForMember(type => type.Key, expression => expression.Ignore())
|
||||
.ForMember(type => type.HelpText, expression => expression.Ignore())
|
||||
.ForMember(type => type.HasIdentity, expression => expression.Ignore())
|
||||
|
||||
Reference in New Issue
Block a user