diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index ba3cac7433..db5323eede 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -423,6 +423,11 @@ namespace Umbraco.Web #region Content + public IPublishedContent TypedContent(object id) + { + return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); + } + public IPublishedContent TypedContent(int id) { return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); @@ -433,6 +438,11 @@ namespace Umbraco.Web return TypedDocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); } + public IEnumerable TypedContent(params object[] ids) + { + return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); + } + public IEnumerable TypedContent(params int[] ids) { return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); @@ -443,6 +453,11 @@ namespace Umbraco.Web return TypedDocumentsbyIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); } + public IEnumerable TypedContent(IEnumerable ids) + { + return TypedContent(ids.ToArray()); + } + public IEnumerable TypedContent(IEnumerable ids) { return TypedContent(ids.ToArray()); @@ -453,6 +468,11 @@ namespace Umbraco.Web return TypedContent(ids.ToArray()); } + public dynamic Content(object id) + { + return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); + } + public dynamic Content(int id) { return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); @@ -463,6 +483,11 @@ namespace Umbraco.Web return DocumentById(id, PublishedContentStoreResolver.Current.PublishedContentStore); } + public dynamic Content(params object[] ids) + { + return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); + } + public dynamic Content(params int[] ids) { return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); @@ -473,6 +498,11 @@ namespace Umbraco.Web return DocumentByIds(PublishedContentStoreResolver.Current.PublishedContentStore, ids); } + public dynamic Content(IEnumerable ids) + { + return Content(ids.ToArray()); + } + public dynamic Content(IEnumerable ids) { return Content(ids.ToArray()); @@ -487,6 +517,21 @@ namespace Umbraco.Web #region Media + /// + /// Overloaded method accepting an 'object' type + /// + /// + /// + /// + /// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass + /// this result in to this method. + /// This method will throw an exception if the value is not of type int or string. + /// + public IPublishedContent TypedMedia(object id) + { + return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); + } + public IPublishedContent TypedMedia(int id) { return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); @@ -497,6 +542,11 @@ namespace Umbraco.Web return TypedDocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); } + public IEnumerable TypedMedia(params object[] ids) + { + return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); + } + public IEnumerable TypedMedia(params int[] ids) { return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); @@ -507,6 +557,11 @@ namespace Umbraco.Web return TypedDocumentsbyIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); } + public IEnumerable TypedMedia(IEnumerable ids) + { + return TypedMedia(ids.ToArray()); + } + public IEnumerable TypedMedia(IEnumerable ids) { return TypedMedia(ids.ToArray()); @@ -517,6 +572,11 @@ namespace Umbraco.Web return TypedMedia(ids.ToArray()); } + public dynamic Media(object id) + { + return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); + } + public dynamic Media(int id) { return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); @@ -527,6 +587,11 @@ namespace Umbraco.Web return DocumentById(id, PublishedMediaStoreResolver.Current.PublishedMediaStore); } + public dynamic Media(params object[] ids) + { + return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); + } + public dynamic Media(params int[] ids) { return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); @@ -537,6 +602,11 @@ namespace Umbraco.Web return DocumentByIds(PublishedMediaStoreResolver.Current.PublishedMediaStore, ids); } + public dynamic Media(IEnumerable ids) + { + return Media(ids.ToArray()); + } + public dynamic Media(IEnumerable ids) { return Media(ids.ToArray()); @@ -551,6 +621,26 @@ namespace Umbraco.Web #region Used by Content/Media + /// + /// Overloaded method accepting an 'object' type + /// + /// + /// + /// + /// + /// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass + /// this result in to this method. + /// This method will throw an exception if the value is not of type int or string. + /// + private IPublishedContent TypedDocumentById(object id, IPublishedStore store) + { + if (id is string) + return TypedDocumentById((string)id, store); + if (id is int) + return TypedDocumentById((int)id, store); + throw new InvalidOperationException("The value of parameter 'id' must be either a string or an integer"); + } + private IPublishedContent TypedDocumentById(int id, IPublishedStore store) { var doc = store.GetDocumentById(UmbracoContext.Current, id); @@ -565,6 +655,22 @@ namespace Umbraco.Web : null; } + /// + /// Overloaded method accepting an 'object' type + /// + /// + /// + /// + /// + /// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass + /// this result in to this method. + /// This method will throw an exception if the value is not of type int or string. + /// + private IEnumerable TypedDocumentsbyIds(IPublishedStore store, params object[] ids) + { + return ids.Select(eachId => TypedDocumentById(eachId, store)); + } + private IEnumerable TypedDocumentsbyIds(IPublishedStore store, params int[] ids) { return ids.Select(eachId => TypedDocumentById(eachId, store)); @@ -575,6 +681,26 @@ namespace Umbraco.Web return ids.Select(eachId => TypedDocumentById(eachId, store)); } + /// + /// Overloaded method accepting an 'object' type + /// + /// + /// + /// + /// + /// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass + /// this result in to this method. + /// This method will throw an exception if the value is not of type int or string. + /// + private dynamic DocumentById(object id, IPublishedStore store) + { + if (id is string) + return DocumentById((string)id, store); + if (id is int) + return DocumentById((int)id, store); + throw new InvalidOperationException("The value of parameter 'id' must be either a string or an integer"); + } + private dynamic DocumentById(int id, IPublishedStore store) { var doc = store.GetDocumentById(UmbracoContext.Current, id); @@ -591,6 +717,25 @@ namespace Umbraco.Web : new DynamicNull(); } + /// + /// Overloaded method accepting an 'object' type + /// + /// + /// + /// + /// + /// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass + /// this result in to this method. + /// This method will throw an exception if the value is not of type int or string. + /// + private dynamic DocumentByIds(IPublishedStore store, params object[] ids) + { + var nodes = ids.Select(eachId => DocumentById(eachId, store)) + .Where(x => !TypeHelper.IsTypeAssignableFrom(x)) + .Cast(); + return new DynamicPublishedContentList(nodes); + } + private dynamic DocumentByIds(IPublishedStore store, params int[] ids) { var nodes = ids.Select(eachId => DocumentById(eachId, store))