From 9b498b8471e99062eb8eed810032a170b8660806 Mon Sep 17 00:00:00 2001 From: Matt Cheale Date: Fri, 2 Sep 2016 14:50:54 +0100 Subject: [PATCH] U4-8937 ContentController.PostSort is not honouring the passed sorted ids. * Updates media to content for comments and logging. * Adds sorting of the retrieved content items to match the passed sort order before persisting. --- src/Umbraco.Web/Editors/ContentController.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index d003636aac..e0f40f7a62 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -467,7 +467,7 @@ namespace Umbraco.Web.Editors } /// - /// Change the sort order for media + /// Change the sort order for content /// /// /// @@ -485,23 +485,30 @@ namespace Umbraco.Web.Editors return Request.CreateResponse(HttpStatusCode.OK); } - var contentService = Services.ContentService; - var sortedContent = new List(); try { - sortedContent.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); + var contentService = Services.ContentService; + var content = new List(); + content.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); + + var sortedList = new List(sorted.IdSortOrder); + var sortedContent = from o in sortedList + join con in content + on o equals con.Id + orderby sortedList.IndexOf(o) + select con; // Save content with new sort order and update content xml in db accordingly if (contentService.Sort(sortedContent) == false) { - LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled"); + LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled"); return Request.CreateValidationErrorResponse("Content sorting failed, this was probably caused by an event being cancelled"); } return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { - LogHelper.Error("Could not update content sort order", ex); + LogHelper.Error("Could not update content sort order", ex); throw; } }