From 9162be9fb0aaa8fdb87490a832be76d3b422f944 Mon Sep 17 00:00:00 2001 From: Callum Whyte Date: Fri, 27 Jul 2018 13:01:54 +0100 Subject: [PATCH] Updating template query builder to use new APIs --- .../Editors/TemplateQueryController.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web/Editors/TemplateQueryController.cs b/src/Umbraco.Web/Editors/TemplateQueryController.cs index 26ca518259..e38c0a1b26 100644 --- a/src/Umbraco.Web/Editors/TemplateQueryController.cs +++ b/src/Umbraco.Web/Editors/TemplateQueryController.cs @@ -1,13 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Services; +using Umbraco.Web.Models.TemplateQuery; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; -using System; -using System.Diagnostics; -using Umbraco.Core.Models.PublishedContent; -using Umbraco.Web.Models.TemplateQuery; -using Umbraco.Core.Services; namespace Umbraco.Web.Editors { @@ -66,7 +66,7 @@ namespace Umbraco.Web.Editors var sb = new StringBuilder(); var indention = Environment.NewLine + "\t\t\t\t\t\t"; - sb.Append("Model.Content.Site()"); + sb.Append("Model.Root()"); var timer = new Stopwatch(); @@ -103,7 +103,7 @@ namespace Umbraco.Web.Editors { // we did not find the path sb.Clear(); - sb.AppendFormat("Umbraco.TypedContent({0})", model.Source.Id); + sb.AppendFormat("Umbraco.Content({0})", model.Source.Id); pointerNode = targetNode; } } @@ -195,10 +195,16 @@ namespace Umbraco.Web.Editors timer.Stop(); - var direction = model.Sort.Direction == "ascending" ? string.Empty : " desc"; - sb.Append(indention); - sb.AppendFormat(".OrderBy(\"{0}{1}\")", model.Sort.Property.Alias, direction); + + if (model.Sort.Direction == "ascending") + { + sb.AppendFormat(".OrderBy(x => x.{0})", model.Sort.Property.Alias); + } + else + { + sb.AppendFormat(".OrderByDescending(x => x.{0})", model.Sort.Property.Alias); + } } if (model.Take > 0) @@ -293,7 +299,7 @@ namespace Umbraco.Web.Editors public IEnumerable GetContentTypes() { var contentTypes = Services.ContentTypeService.GetAll() - .Select(x => new ContentTypeModel { Alias = x.Alias, Name = Services.TextService.Localize("template/contentOfType", tokens: new string[] { x.Name } ) }) + .Select(x => new ContentTypeModel { Alias = x.Alias, Name = Services.TextService.Localize("template/contentOfType", tokens: new string[] { x.Name }) }) .OrderBy(x => x.Name).ToList(); contentTypes.Insert(0, new ContentTypeModel { Alias = string.Empty, Name = Services.TextService.Localize("template/allContent") });