From cf6775ec3191e0637e39d139b65e80413147825d Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 17 Apr 2014 18:05:12 +1000 Subject: [PATCH] moves an internal class --- .../DataTypeDefinitionRepository.cs | 40 ++++++++++++++++++- src/Umbraco.Core/Services/DataTypeService.cs | 36 +---------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs index 2da9829ece..dc73f3584a 100644 --- a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs @@ -462,7 +462,7 @@ AND umbracoNode.id <> @id", //go get the data var dtos = Database.Fetch("WHERE datatypeNodeId = @Id", new { Id = dataTypeId }); var list = dtos.Select(x => new Tuple(new PreValue(x.Id, x.Value), x.Alias, x.SortOrder)).ToList(); - var collection = DataTypeService.PreValueConverter.ConvertToPreValuesCollection(list); + var collection = PreValueConverter.ConvertToPreValuesCollection(list); //now create the cache key, this needs to include all pre-value ids so that we can use this cached item in the GetPreValuesAsString method //the key will be: "UmbracoPreValDATATYPEID-CSVOFPREVALIDS @@ -600,7 +600,43 @@ AND id <> @id", Database.Update(dto); } } - + + internal static class PreValueConverter + { + /// + /// Converts the tuple to a pre-value collection + /// + /// + /// + internal static PreValueCollection ConvertToPreValuesCollection(IEnumerable> list) + { + //now we need to determine if they are dictionary based, otherwise they have to be array based + var dictionary = new Dictionary(); + + //need to check all of the keys, if there's only one and it is empty then it's an array + var keys = list.Select(x => x.Item2).Distinct().ToArray(); + if (keys.Length == 1 && keys[0].IsNullOrWhiteSpace()) + { + return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1)); + } + + foreach (var item in list + .OrderBy(x => x.Item3) //we'll order them first so we maintain the order index in the dictionary + .GroupBy(x => x.Item2)) //group by alias + { + if (item.Count() > 1) + { + //if there's more than 1 item per key, then it cannot be a dictionary, just return the array + return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1)); + } + + dictionary.Add(item.Key, item.First().Item1); + } + + return new PreValueCollection(dictionary); + } + } + } diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index b7a22be6fd..936e3ca89a 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -371,40 +371,6 @@ namespace Umbraco.Core.Services public static event TypedEventHandler> Saved; #endregion - internal static class PreValueConverter - { - /// - /// Converts the tuple to a pre-value collection - /// - /// - /// - internal static PreValueCollection ConvertToPreValuesCollection(IEnumerable> list) - { - //now we need to determine if they are dictionary based, otherwise they have to be array based - var dictionary = new Dictionary(); - - //need to check all of the keys, if there's only one and it is empty then it's an array - var keys = list.Select(x => x.Item2).Distinct().ToArray(); - if (keys.Length == 1 && keys[0].IsNullOrWhiteSpace()) - { - return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1)); - } - - foreach (var item in list - .OrderBy(x => x.Item3) //we'll order them first so we maintain the order index in the dictionary - .GroupBy(x => x.Item2)) //group by alias - { - if (item.Count() > 1) - { - //if there's more than 1 item per key, then it cannot be a dictionary, just return the array - return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1)); - } - - dictionary.Add(item.Key, item.First().Item1); - } - - return new PreValueCollection(dictionary); - } - } + } } \ No newline at end of file