diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 08147a48a9..8fbc8c8305 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -2406,6 +2406,8 @@ public class ContentService : RepositoryService, IContentService using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { + var parentId = content.ParentId; + scope.WriteLock(Constants.Locks.ContentTree); var originalPath = content.Path; @@ -2438,6 +2440,14 @@ public class ContentService : RepositoryService, IContentService movingToRecycleBinNotification)); Audit(AuditType.Move, userId, content.Id, "Moved to recycle bin"); + // sort the children of the parent after deleting the content + IQuery childQuery = Query().Where(x => x.ParentId == parentId && x.Id != content.Id); + IEnumerable children = _documentRepository.Get(childQuery); + if(children.Any()) + { + Sort(children, userId); + } + scope.Complete(); } @@ -2459,6 +2469,8 @@ public class ContentService : RepositoryService, IContentService { EventMessages eventMessages = EventMessagesFactory.Get(); + var parentIdBeforeMove = content.ParentId; + if (content.ParentId == parentId) { return OperationResult.Succeed(eventMessages); @@ -2523,6 +2535,14 @@ public class ContentService : RepositoryService, IContentService Audit(AuditType.Move, userId, content.Id); + // sort the children of the old parent after moving the content + IQuery childQuery = Query().Where(x => x.ParentId == parentIdBeforeMove && x.Id != content.Id); + IEnumerable children = _documentRepository.Get(childQuery); + if (children.Any()) + { + Sort(children, userId); + } + scope.Complete(); return OperationResult.Succeed(eventMessages); }