From f227f2ed616dafd2378c7b6fbd2903ef8d78ebd2 Mon Sep 17 00:00:00 2001 From: Mario Lopez Date: Thu, 28 Feb 2019 13:55:14 +1100 Subject: [PATCH 1/2] added Content and Media Udi overloads --- src/Umbraco.Web/UmbracoHelper.cs | 98 +++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index b2045bacfb..12a985c02d 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -5,11 +5,9 @@ using System.Web; using System.Xml.XPath; using Umbraco.Core; using Umbraco.Core.Dictionary; -using Umbraco.Core.Exceptions; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Xml; -using Umbraco.Web.Routing; using Umbraco.Web.Security; namespace Umbraco.Web @@ -367,6 +365,30 @@ namespace Umbraco.Web return ContentForObjects(ids); } + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable Content(params Udi[] ids) + { + if (!(ids is IEnumerable udis)) return null; + + return ids.Select(id => ContentQuery.Content(id)); + } + + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable Content(params GuidUdi[] ids) + { + return ids.Select(id => ContentQuery.Content(id)); + } + private IEnumerable ContentForObjects(IEnumerable ids) { var idsA = ids.ToArray(); @@ -418,6 +440,29 @@ namespace Umbraco.Web { return ContentForObjects(ids); } + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable Content(IEnumerable ids) + { + if (!(ids is IEnumerable udis)) return null; + + return ids.Select(id => ContentQuery.Content(id)); + } + + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable Content(IEnumerable ids) + { + return ids.Select(id => ContentQuery.Content(id)); + } /// /// Gets the contents corresponding to the identifiers. @@ -634,6 +679,31 @@ namespace Umbraco.Web return MediaForObjects(ids); } + + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable Media(params Udi[] ids) + { + if (!(ids is IEnumerable udis)) return null; + + return ids.Select(id => ContentQuery.Media(id)); + } + + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable Media(params GuidUdi[] ids) + { + return ids.Select(id => ContentQuery.Media(id)); + } + /// /// Gets the medias corresponding to the identifiers. /// @@ -656,6 +726,30 @@ namespace Umbraco.Web return ContentQuery.Media(ids); } + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable Media(IEnumerable ids) + { + if (!(ids is IEnumerable udis)) return null; + + return ids.Select(id => ContentQuery.Media(id)); + } + + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable Media(IEnumerable ids) + { + return ids.Select(id => ContentQuery.Media(id)); + } + /// /// Gets the medias corresponding to the identifiers. /// From 093b57505a3e27e3709d412e90dbd738091632e2 Mon Sep 17 00:00:00 2001 From: Mario Lopez Date: Thu, 28 Feb 2019 16:50:28 +1100 Subject: [PATCH 2/2] simplified GuidUdi checking. --- src/Umbraco.Web/UmbracoHelper.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 12a985c02d..12d4ce1d76 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -373,9 +373,7 @@ namespace Umbraco.Web /// If an identifier does not match an existing content, it will be missing in the returned value. public IEnumerable Content(params Udi[] ids) { - if (!(ids is IEnumerable udis)) return null; - - return ids.Select(id => ContentQuery.Content(id)); + return ids.Select(id => ContentQuery.Content(id)).WhereNotNull(); } /// @@ -447,10 +445,8 @@ namespace Umbraco.Web /// The existing contents corresponding to the identifiers. /// If an identifier does not match an existing content, it will be missing in the returned value. public IEnumerable Content(IEnumerable ids) - { - if (!(ids is IEnumerable udis)) return null; - - return ids.Select(id => ContentQuery.Content(id)); + { + return ids.Select(id => ContentQuery.Content(id)).WhereNotNull(); } /// @@ -688,9 +684,7 @@ namespace Umbraco.Web /// If an identifier does not match an existing media, it will be missing in the returned value. public IEnumerable Media(params Udi[] ids) { - if (!(ids is IEnumerable udis)) return null; - - return ids.Select(id => ContentQuery.Media(id)); + return ids.Select(id => ContentQuery.Media(id)).WhereNotNull(); } /// @@ -734,9 +728,7 @@ namespace Umbraco.Web /// If an identifier does not match an existing media, it will be missing in the returned value. public IEnumerable Media(IEnumerable ids) { - if (!(ids is IEnumerable udis)) return null; - - return ids.Select(id => ContentQuery.Media(id)); + return ids.Select(id => ContentQuery.Media(id)).WhereNotNull(); } ///