diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 8ddc81fc92..e41ff06429 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -30,13 +30,13 @@ namespace Umbraco.Core.Models private PropertyGroupCollection _propertyGroups; private List _contentTypeComposition; private IEnumerable _allowedTemplates; - private IEnumerable _allowedContentTypes; + private IEnumerable _allowedContentTypes; public ContentType(int parentId) { _parentId = parentId; _allowedTemplates = new List(); - _allowedContentTypes = new List(); + _allowedContentTypes = new List(); _propertyGroups = new PropertyGroupCollection(); _contentTypeComposition = new List(); } @@ -54,7 +54,7 @@ namespace Umbraco.Core.Models private static readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo(x => x.UserId); private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo(x => x.Trashed); private static readonly PropertyInfo AllowedTemplatesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedTemplates); - private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedContentTypes); + private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedContentTypes); private static readonly PropertyInfo ContentTypeCompositionSelector = ExpressionHelper.GetPropertyInfo>(x => x.ContentTypeComposition); private readonly static PropertyInfo PropertyGroupCollectionSelector = ExpressionHelper.GetPropertyInfo(x => x.PropertyGroups); void PropertyGroupsChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -249,7 +249,7 @@ namespace Umbraco.Core.Models /// Gets or sets a list of integer Ids for allowed ContentTypes /// [DataMember] - public IEnumerable AllowedContentTypes + public IEnumerable AllowedContentTypes { get { return _allowedContentTypes; } set diff --git a/src/Umbraco.Core/Models/ContentTypeSort.cs b/src/Umbraco.Core/Models/ContentTypeSort.cs new file mode 100644 index 0000000000..af700cca45 --- /dev/null +++ b/src/Umbraco.Core/Models/ContentTypeSort.cs @@ -0,0 +1,20 @@ +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a POCO for setting sort order on a ContentType reference + /// + public class ContentTypeSort : IValueObject + { + /// + /// Gets or sets the Id of the ContentType + /// + public int Id { get; set; } + + /// + /// Gets or sets the Sort Order of the ContentType + /// + public int SortOrder { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/IContentTypeBase.cs b/src/Umbraco.Core/Models/IContentTypeBase.cs index 93ad407db6..973b99c592 100644 --- a/src/Umbraco.Core/Models/IContentTypeBase.cs +++ b/src/Umbraco.Core/Models/IContentTypeBase.cs @@ -62,7 +62,7 @@ namespace Umbraco.Core.Models /// /// Gets or Sets a list of integer Ids of the ContentTypes allowed under the ContentType /// - IEnumerable AllowedContentTypes { get; set; } + IEnumerable AllowedContentTypes { get; set; } /// /// Gets or Sets a collection of Property Groups diff --git a/src/Umbraco.Core/Models/MediaType.cs b/src/Umbraco.Core/Models/MediaType.cs index 2d1ecbfa55..354982b85d 100644 --- a/src/Umbraco.Core/Models/MediaType.cs +++ b/src/Umbraco.Core/Models/MediaType.cs @@ -27,12 +27,12 @@ namespace Umbraco.Core.Models private int _userId; private bool _trashed; private PropertyGroupCollection _propertyGroups; - private IEnumerable _allowedContentTypes; + private IEnumerable _allowedContentTypes; public MediaType(int parentId) { _parentId = parentId; - _allowedContentTypes = new List(); + _allowedContentTypes = new List(); _propertyGroups = new PropertyGroupCollection(); } @@ -47,7 +47,7 @@ namespace Umbraco.Core.Models private static readonly PropertyInfo ThumbnailSelector = ExpressionHelper.GetPropertyInfo(x => x.Thumbnail); private static readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo(x => x.UserId); private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo(x => x.Trashed); - private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedContentTypes); + private static readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedContentTypes); private readonly static PropertyInfo PropertyGroupCollectionSelector = ExpressionHelper.GetPropertyInfo(x => x.PropertyGroups); void PropertyGroupsChanged(object sender, NotifyCollectionChangedEventArgs e) { @@ -214,7 +214,7 @@ namespace Umbraco.Core.Models /// Gets or sets a list of integer Ids for allowed ContentTypes /// [DataMember] - public IEnumerable AllowedContentTypes + public IEnumerable AllowedContentTypes { get { return _allowedContentTypes; } set diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index 99d901d298..c226716c62 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -14,6 +14,7 @@ namespace Umbraco.Core.Models public class PropertyGroup : Entity, IEquatable { private string _name; + private int? _parentId; private int _sortOrder; private PropertyTypeCollection _propertyTypes; @@ -27,6 +28,7 @@ namespace Umbraco.Core.Models } private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); + private static readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); private readonly static PropertyInfo PropertyTypeCollectionSelector = ExpressionHelper.GetPropertyInfo(x => x.PropertyTypes); void PropertyTypesChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -48,6 +50,20 @@ namespace Umbraco.Core.Models } } + /// + /// Gets or sets the Name of the Group, which corresponds to the Tab-name in the UI + /// + [DataMember] + public int? ParentId + { + get { return _parentId; } + set + { + _parentId = value; + OnPropertyChanged(ParentIdSelector); + } + } + /// /// Gets or sets the Sort Order of the Group /// diff --git a/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs new file mode 100644 index 0000000000..0417aaad1b --- /dev/null +++ b/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs @@ -0,0 +1,15 @@ +using Umbraco.Core.Persistence; + +namespace Umbraco.Core.Models.Rdbms +{ + [TableName("cmsContentType2ContentType")] + [ExplicitColumns] + internal class ContentType2ContentTypeDto + { + [Column("parentContentTypeId")] + public int ParentId { get; set; } + + [Column("childContentTypeId")] + public int ChildId { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs index 6229e2a042..9c3e2ad6a8 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs @@ -12,5 +12,8 @@ namespace Umbraco.Core.Models.Rdbms [Column("AllowedId")] public int AllowedId { get; set; } + + [Column("SortOrder")] + public int SortOrder { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs index 9428c36267..1d97d24369 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs @@ -25,8 +25,11 @@ namespace Umbraco.Core.Models.Rdbms [Column("description")] public string Description { get; set; } - [Column("masterContentType")] - public int? MasterContentType { get; set; } + [Column("isContainer")] + public bool IsContainer { get; set; } + + [Column("allowAtRoot")] + public bool AllowAtRoot { get; set; } [ResultColumn] public NodeDto NodeDto { get; set; } diff --git a/src/Umbraco.Core/Models/Rdbms/PropertyTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/PropertyTypeDto.cs index 45a23fa38d..a870c5717f 100644 --- a/src/Umbraco.Core/Models/Rdbms/PropertyTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/PropertyTypeDto.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Models.Rdbms [Column("contentTypeId")] public int ContentTypeId { get; set; } - [Column("tabId")] + [Column("propertyTypeGroupId")] public int? TabId { get; set; } [Column("Alias")] diff --git a/src/Umbraco.Core/Models/Rdbms/TabDto.cs b/src/Umbraco.Core/Models/Rdbms/PropertyTypeGroupDto.cs similarity index 68% rename from src/Umbraco.Core/Models/Rdbms/TabDto.cs rename to src/Umbraco.Core/Models/Rdbms/PropertyTypeGroupDto.cs index e2837eed13..12039168ab 100644 --- a/src/Umbraco.Core/Models/Rdbms/TabDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/PropertyTypeGroupDto.cs @@ -3,14 +3,17 @@ using Umbraco.Core.Persistence; namespace Umbraco.Core.Models.Rdbms { - [TableName("cmsTab")] - [PrimaryKey("id")] + [TableName("cmsPropertyTypeGroup")] + [PrimaryKey("id", autoIncrement = true)] [ExplicitColumns] - internal class TabDto + internal class PropertyTypeGroupDto { [Column("id")] public int Id { get; set; } + [Column("parentGroupId")] + public int? ParentGroupId { get; set; } + [Column("contenttypeNodeId")] public int ContentTypeNodeId { get; set; } diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs index 80b7bccfb5..46f4753ca6 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Models.Rdbms; namespace Umbraco.Core.Persistence.Factories { - internal class PropertyGroupFactory : IEntityFactory, IEnumerable> + internal class PropertyGroupFactory : IEntityFactory, IEnumerable> { private readonly int _id; @@ -16,18 +16,19 @@ namespace Umbraco.Core.Persistence.Factories #region Implementation of IEntityFactory,IEnumerable> - public IEnumerable BuildEntity(IEnumerable dto) + public IEnumerable BuildEntity(IEnumerable dto) { var propertyGroups = new PropertyGroupCollection(); - foreach (var tabDto in dto) + foreach (var groupDto in dto) { var group = new PropertyGroup(); - group.Id = tabDto.Id; - group.Name = tabDto.Text; - group.SortOrder = tabDto.SortOrder; + group.Id = groupDto.Id; + group.Name = groupDto.Text; + group.ParentId = groupDto.ParentGroupId; + group.SortOrder = groupDto.SortOrder; group.PropertyTypes = new PropertyTypeCollection(); - foreach (var typeDto in tabDto.PropertyTypeDtos) + foreach (var typeDto in groupDto.PropertyTypeDtos) { group.PropertyTypes.Add(new PropertyType(typeDto.DataTypeDto.ControlId, typeDto.DataTypeDto.DbType.EnumParse(true)) @@ -50,28 +51,29 @@ namespace Umbraco.Core.Persistence.Factories return propertyGroups; } - public IEnumerable BuildDto(IEnumerable entity) + public IEnumerable BuildDto(IEnumerable entity) { - return entity.Select(propertyGroup => BuildTabDto(propertyGroup)).ToList(); + return entity.Select(propertyGroup => BuildGroupDto(propertyGroup)).ToList(); } #endregion - internal TabDto BuildTabDto(PropertyGroup propertyGroup) + internal PropertyTypeGroupDto BuildGroupDto(PropertyGroup propertyGroup) { - var tabDto = new TabDto + var dto = new PropertyTypeGroupDto { ContentTypeNodeId = _id, SortOrder = propertyGroup.SortOrder, - Text = propertyGroup.Name + Text = propertyGroup.Name, + ParentGroupId = propertyGroup.ParentId }; if (propertyGroup.HasIdentity) - tabDto.Id = propertyGroup.Id; + dto.Id = propertyGroup.Id; - tabDto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType)).ToList(); + dto.PropertyTypeDtos = propertyGroup.PropertyTypes.Select(propertyType => BuildPropertyTypeDto(propertyGroup.Id, propertyType)).ToList(); - return tabDto; + return dto; } internal PropertyTypeDto BuildPropertyTypeDto(int tabId, PropertyType propertyType) diff --git a/src/Umbraco.Core/Persistence/Relators/TabPropertyTypeRelator.cs b/src/Umbraco.Core/Persistence/Relators/TabPropertyTypeRelator.cs index 295e39dccc..a9d58489e6 100644 --- a/src/Umbraco.Core/Persistence/Relators/TabPropertyTypeRelator.cs +++ b/src/Umbraco.Core/Persistence/Relators/TabPropertyTypeRelator.cs @@ -5,9 +5,9 @@ namespace Umbraco.Core.Persistence.Relators { internal class TabPropertyTypeRelator { - internal TabDto current; + internal PropertyTypeGroupDto current; - internal TabDto Map(TabDto a, PropertyTypeDto p, DataTypeDto d) + internal PropertyTypeGroupDto Map(PropertyTypeGroupDto a, PropertyTypeDto p, DataTypeDto d) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null @@ -19,23 +19,23 @@ namespace Umbraco.Core.Persistence.Relators if (p.DataTypeId == d.DataTypeId) p.DataTypeDto = d; - // Is this the same Tab as the current one we're processing + // Is this the same Group as the current one we're processing if (current != null && current.Id == a.Id) { - // Yes, just add this PropertyType to the current Tab's collection of PropertyTypes + // Yes, just add this PropertyType to the current Group's collection of PropertyTypes current.PropertyTypeDtos.Add(p); - // Return null to indicate we're not done with this Tab yet + // Return null to indicate we're not done with this Group yet return null; } - // This is a different Tab to the current one, or this is the + // This is a different Group to the current one, or this is the // first time through and we don't have a Tab yet - // Save the current Tab + // Save the current Group var prev = current; - // Setup the new current Tab + // Setup the new current Group current = a; current.PropertyTypeDtos = new List(); current.PropertyTypeDtos.Add(p); diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs index 4d5b587917..6ea8e1ce8c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs @@ -33,19 +33,24 @@ namespace Umbraco.Core.Persistence.Repositories var contentTypeSql = GetBaseQuery(false); contentTypeSql.Append(GetBaseWhereClause(id)); - var documentTypeDto = Database.Query(contentTypeSql).FirstOrDefault(); + var dto = Database.Query(contentTypeSql).FirstOrDefault(); - if (documentTypeDto == null) + if (dto == null) return null; - //TODO Get ContentType composition according to new table - var factory = new ContentTypeFactory(NodeObjectTypeId); - var contentType = factory.BuildEntity(documentTypeDto); + var contentType = factory.BuildEntity(dto); contentType.AllowedContentTypes = GetAllowedContentTypeIds(id); contentType.PropertyGroups = GetPropertyGroupCollection(id); + var list = Database.Fetch("WHERE childContentTypeId = @Id"); + foreach (var contentTypeDto in list) + { + bool result = contentType.AddContentType(Get(contentTypeDto.ParentId)); + //Do something if adding fails? (Should hopefully not be possible unless someone create a circular reference) + } + ((ContentType)contentType).ResetDirtyProperties(); return contentType; } @@ -172,12 +177,19 @@ namespace Umbraco.Core.Persistence.Repositories //TODO Insert new DocumentType entries - NOTE only seems relevant as long as Templates resides in the DB? //TODO Insert allowed Templates - //TODO Insert ContentType composition in new table + + //Insert ContentType composition in new table + foreach (var composition in entity.ContentTypeComposition) + { + if(composition.Id == entity.Id) continue;//Just to ensure that we aren't creating a reference to ourself. + + Database.Insert(new ContentType2ContentTypeDto { ParentId = composition.Id, ChildId = entity.Id}); + } //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { - Database.Insert(new ContentTypeAllowedContentTypeDto {Id = entity.Id, AllowedId = allowedContentType}); + Database.Insert(new ContentTypeAllowedContentTypeDto {Id = entity.Id, AllowedId = allowedContentType.Id, SortOrder = allowedContentType.SortOrder}); } var propertyFactory = new PropertyGroupFactory(nodeDto.NodeId); @@ -185,7 +197,7 @@ namespace Umbraco.Core.Persistence.Repositories //Insert Tabs foreach (var propertyGroup in entity.PropertyGroups) { - var tabDto = propertyFactory.BuildTabDto(propertyGroup); + var tabDto = propertyFactory.BuildGroupDto(propertyGroup); var primaryKey = Convert.ToInt32(Database.Insert(tabDto)); propertyGroup.Id = primaryKey;//Set Id on PropertyGroup } @@ -225,15 +237,21 @@ namespace Umbraco.Core.Persistence.Repositories //TODO Update new DocumentType entries - NOTE only seems relevant as long as Templates resides in the DB? //TODO Update allowed Templates - //TODO Update ContentType composition in new table + + //Delete the ContentType composition entries before adding the updated collection + Database.Delete("WHERE childContentTypeId = @Id", new { Id = entity.Id }); + //Update ContentType composition in new table + foreach (var composition in entity.ContentTypeComposition) + { + Database.Insert(new ContentType2ContentTypeDto { ParentId = composition.Id, ChildId = entity.Id }); + } //Delete the allowed content type entries before adding the updated collection Database.Delete("WHERE Id = @Id", new {Id = entity.Id}); - //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { - Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType }); + Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType.Id, SortOrder = allowedContentType.SortOrder}); } //Check Dirty properties for Tabs/Groups and PropertyTypes - insert and delete accordingly @@ -248,18 +266,18 @@ namespace Umbraco.Core.Persistence.Repositories Database.Delete("WHERE contentTypeId = @Id AND Alias = @Alias", new { Id = entity.Id, Alias = alias }); } //Delete Tabs/Groups by excepting entries from db with entries from collections - var dbPropertyGroups = Database.Fetch("WHERE contenttypeNodeId = @Id", new { Id = entity.Id }).Select(x => x.Text); + var dbPropertyGroups = Database.Fetch("WHERE contenttypeNodeId = @Id", new { Id = entity.Id }).Select(x => x.Text); var entityPropertyGroups = entity.PropertyGroups.Select(x => x.Name); var tabs = dbPropertyGroups.Except(entityPropertyGroups); foreach (var tabName in tabs) { - Database.Delete("WHERE contenttypeNodeId = @Id AND text = @Name", new { Id = entity.Id, Name = tabName }); + Database.Delete("WHERE contenttypeNodeId = @Id AND text = @Name", new { Id = entity.Id, Name = tabName }); } //Run through all groups and types to insert or update entries foreach (var propertyGroup in entity.PropertyGroups) { - var tabDto = propertyFactory.BuildTabDto(propertyGroup); + var tabDto = propertyFactory.BuildGroupDto(propertyGroup); int groupPrimaryKey = propertyGroup.HasIdentity ? Database.Update(tabDto) : Convert.ToInt32(Database.Insert(tabDto)); @@ -286,7 +304,7 @@ namespace Umbraco.Core.Persistence.Repositories #endregion - private IEnumerable GetAllowedContentTypeIds(int id) + private IEnumerable GetAllowedContentTypeIds(int id) { var allowedContentTypesSql = new Sql(); allowedContentTypesSql.Select("*"); @@ -294,7 +312,7 @@ namespace Umbraco.Core.Persistence.Repositories allowedContentTypesSql.Where("[cmsContentTypeAllowedContentType].[Id] = @Id", new { Id = id }); var allowedContentTypeDtos = Database.Fetch(allowedContentTypesSql); - return allowedContentTypeDtos.Select(x => x.AllowedId).ToList(); + return allowedContentTypeDtos.Select(x => new ContentTypeSort { Id = x.AllowedId, SortOrder = x.SortOrder }).ToList(); } private PropertyGroupCollection GetPropertyGroupCollection(int id) @@ -306,10 +324,10 @@ namespace Umbraco.Core.Persistence.Repositories propertySql.InnerJoin("cmsDataType ON [cmsPropertyType].[dataTypeId] = [cmsDataType].[nodeId]"); propertySql.Where("[cmsPropertyType].[contentTypeId] = @Id", new { Id = id }); - var tabDtos = Database.Fetch(new TabPropertyTypeRelator().Map, propertySql); + var dtos = Database.Fetch(new TabPropertyTypeRelator().Map, propertySql); var propertyFactory = new PropertyGroupFactory(id); - var propertyGroups = propertyFactory.BuildEntity(tabDtos); + var propertyGroups = propertyFactory.BuildEntity(dtos); return new PropertyGroupCollection(propertyGroups); } } diff --git a/src/Umbraco.Core/Persistence/Repositories/MediaTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MediaTypeRepository.cs index 89698d1da7..d5dbf4d73c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MediaTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MediaTypeRepository.cs @@ -164,7 +164,7 @@ namespace Umbraco.Core.Persistence.Repositories //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { - Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType }); + Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType.Id, SortOrder = allowedContentType.SortOrder}); } } @@ -190,7 +190,7 @@ namespace Umbraco.Core.Persistence.Repositories //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { - Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType }); + Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType.Id, SortOrder = allowedContentType.SortOrder }); } //Check Dirty properties for Tabs/Groups and PropertyTypes - insert and delete accordingly @@ -205,18 +205,18 @@ namespace Umbraco.Core.Persistence.Repositories Database.Delete("WHERE contentTypeId = @Id AND Alias = @Alias", new { Id = entity.Id, Alias = alias }); } //Delete Tabs/Groups by excepting entries from db with entries from collections - var dbPropertyGroups = Database.Fetch("WHERE contenttypeNodeId = @Id", new { Id = entity.Id }).Select(x => x.Text); + var dbPropertyGroups = Database.Fetch("WHERE contenttypeNodeId = @Id", new { Id = entity.Id }).Select(x => x.Text); var entityPropertyGroups = entity.PropertyGroups.Select(x => x.Name); var tabs = dbPropertyGroups.Except(entityPropertyGroups); foreach (var tabName in tabs) { - Database.Delete("WHERE contenttypeNodeId = @Id AND text = @Name", new { Id = entity.Id, Name = tabName }); + Database.Delete("WHERE contenttypeNodeId = @Id AND text = @Name", new { Id = entity.Id, Name = tabName }); } //Run through all groups and types to insert or update entries foreach (var propertyGroup in entity.PropertyGroups) { - var tabDto = propertyFactory.BuildTabDto(propertyGroup); + var tabDto = propertyFactory.BuildGroupDto(propertyGroup); int groupPrimaryKey = propertyGroup.HasIdentity ? Database.Update(tabDto) : Convert.ToInt32(Database.Insert(tabDto)); @@ -243,7 +243,7 @@ namespace Umbraco.Core.Persistence.Repositories #endregion - private IEnumerable GetAllowedContentTypeIds(int id) + private IEnumerable GetAllowedContentTypeIds(int id) { var allowedContentTypesSql = new Sql(); allowedContentTypesSql.Select("*"); @@ -251,7 +251,7 @@ namespace Umbraco.Core.Persistence.Repositories allowedContentTypesSql.Where("[cmsContentTypeAllowedContentType].[Id] = @Id", new { Id = id }); var allowedContentTypeDtos = Database.Fetch(allowedContentTypesSql); - return allowedContentTypeDtos.Select(x => x.AllowedId).ToList(); + return allowedContentTypeDtos.Select(x => new ContentTypeSort { Id = x.AllowedId, SortOrder = x.SortOrder}).ToList(); } private PropertyGroupCollection GetPropertyGroupCollection(int id) @@ -263,7 +263,7 @@ namespace Umbraco.Core.Persistence.Repositories propertySql.InnerJoin("cmsDataType ON [cmsPropertyType].[dataTypeId] = [cmsDataType].[nodeId]"); propertySql.Where("[cmsPropertyType].[contentTypeId] = @Id", new { Id = id }); - var tabDtos = Database.Fetch(new TabPropertyTypeRelator().Map, propertySql); + var tabDtos = Database.Fetch(new TabPropertyTypeRelator().Map, propertySql); var propertyFactory = new PropertyGroupFactory(id); var propertyGroups = propertyFactory.BuildEntity(tabDtos); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index a155e1d2b4..43429738c0 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -76,6 +76,7 @@ + @@ -91,6 +92,8 @@ + + @@ -266,7 +269,6 @@ -