From de53dbffd1bcc79e3dd5063aa1740b28011123b1 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 4 Feb 2015 19:07:51 +0100 Subject: [PATCH] U4-6129 - fix order of EntityService.GetByIds items --- src/Umbraco.Web/Editors/EntityController.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 7cebeb6252..b12d19d032 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -6,6 +6,7 @@ using System.Text; using System.Web.Http; using System.Web.Http.ModelBinding; using AutoMapper; +using ClientDependency.Core; using Examine.LuceneEngine; using Examine.LuceneEngine.Providers; using Newtonsoft.Json; @@ -637,15 +638,20 @@ namespace Umbraco.Web.Editors private IEnumerable GetResultForKeys(IEnumerable keys, UmbracoEntityTypes entityType) { - if (keys.Any() == false) return Enumerable.Empty(); + var keysArray = keys.ToArray(); + if (keysArray.Any() == false) return Enumerable.Empty(); var objectType = ConvertToObjectType(entityType); if (objectType.HasValue) { - var result = Services.EntityService.GetAll(objectType.Value, keys.ToArray()) + var entities = Services.EntityService.GetAll(objectType.Value, keysArray) .WhereNotNull() .Select(Mapper.Map); + // entities are in "some" order, put them back in order + var xref = entities.ToDictionary(x => x.Id); + var result = keysArray.Select(x => xref.ContainsKey(x) ? xref[x] : null).Where(x => x != null); + return result; } //now we need to convert the unknown ones @@ -664,15 +670,20 @@ namespace Umbraco.Web.Editors private IEnumerable GetResultForIds(IEnumerable ids, UmbracoEntityTypes entityType) { - if (ids.Any() == false) return Enumerable.Empty(); + var idsArray = ids.ToArray(); + if (idsArray.Any() == false) return Enumerable.Empty(); var objectType = ConvertToObjectType(entityType); if (objectType.HasValue) { - var result = Services.EntityService.GetAll(objectType.Value, ids.ToArray()) + var entities = Services.EntityService.GetAll(objectType.Value, idsArray) .WhereNotNull() .Select(Mapper.Map); + // entities are in "some" order, put them back in order + var xref = entities.ToDictionary(x => x.Id); + var result = idsArray.Select(x => xref.ContainsKey(x) ? xref[x] : null).Where(x => x != null); + return result; } //now we need to convert the unknown ones