From bc23495632ca10331eeaa415550f5697beeb58d9 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Mon, 14 Jan 2013 14:04:40 -0100 Subject: [PATCH] Adds updating of SortOrder upon moving a document. Related to U4-1461 --- .../Persistence/Repositories/ContentRepository.cs | 2 ++ src/Umbraco.Core/Services/ContentService.cs | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index c798a927dd..0671b4c150 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -280,6 +280,8 @@ namespace Umbraco.Core.Persistence.Repositories { var parent = Database.First("WHERE id = @ParentId", new { ParentId = entity.ParentId }); entity.Path = string.Concat(parent.Path, ",", entity.Id); + var maxSortOrder = Database.ExecuteScalar("SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId", new { ParentId = entity.ParentId }); + entity.SortOrder = maxSortOrder; } var factory = new ContentFactory(NodeObjectTypeId, entity.Id); diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index e9ce6983cf..50c9eaef9a 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -905,9 +905,13 @@ namespace Umbraco.Core.Services /// Optional Id of the User moving the Content public void Move(IContent content, int parentId, int userId = -1) { - //TODO Verify that SortOrder + Path is updated correctly - //TODO Add a check to see if parentId = -20 because then we should change the TrashState - + //This ensures that the correct method is called if this method is used to Move to recycle bin. + if (parentId == -20) + { + MoveToRecycleBin(content, userId); + return; + } + if (Moving.IsRaisedEventCancelled(new MoveEventArgs(content, parentId), this)) return;