diff --git a/CHANGELOG.md b/CHANGELOG.md index 245b815..20472af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.3.3 +* Updates MediaTypeHandler to return null if no media is found rather than returning an object with all null properties + ## v1.3.2 * Updates UmbracoWebContext.GetCurrent to use the PublishedContent from the PublishedContentRequest rather than getting a page by the current id. diff --git a/UmbracoVault/TypeHandlers/MediaTypeHandler.cs b/UmbracoVault/TypeHandlers/MediaTypeHandler.cs index e4ea986..29d7687 100644 --- a/UmbracoVault/TypeHandlers/MediaTypeHandler.cs +++ b/UmbracoVault/TypeHandlers/MediaTypeHandler.cs @@ -16,24 +16,31 @@ public class MediaTypeHandler : ITypeHandler private static IPublishedContent Get(string stringValue) { + if (string.IsNullOrWhiteSpace(stringValue)) + { + return null; + } + var helper = new UmbracoHelper(UmbracoContext.Current); return helper.TypedMedia(stringValue); } public object GetAsType(object input) - { - var result = typeof(T).CreateWithNoParams(); + { + var mediaObject = Get(input?.ToString()); + if (mediaObject == null) + { + return null; + } + var result = typeof(T).CreateWithNoParams(); if (result == null) { throw new ConstructorUnavailableException(typeof(T)); } - var mediaObject = Get(input.ToString()); - if (mediaObject != null) - { - Vault.Context.FillClassProperties(result, (alias, recursive) => mediaObject.GetPropertyValue(alias,recursive)); - } + Vault.Context.FillClassProperties(result, (alias, recursive) => mediaObject.GetPropertyValue(alias,recursive)); + return result; } diff --git a/UmbracoVault/UmbracoVault.nuspec b/UmbracoVault/UmbracoVault.nuspec index 95b6bf9..b2eb456 100644 --- a/UmbracoVault/UmbracoVault.nuspec +++ b/UmbracoVault/UmbracoVault.nuspec @@ -12,8 +12,7 @@ Vault for Umbraco is an easy-to-use, extensible ORM to quickly and easily get strongly-typed Umbraco CMS data into your views. It allows you to create lightly-decorated classes that Vault will understand how to hydrate. This gives you the full view model-style experience in Umbraco that you are accustomed to in MVC, complete with strongly-typed view properties (no more magic strings in your views). Vault for Umbraco is an easy-to-use, extensible ORM to quickly and easily get strongly-typed Umbraco CMS data into your views. - * Updates UmbracoWebContext.GetCurrent to use the PublishedContent from the PublishedContentRequest rather than getting a page by the current id. - * Updated value transformation process to execute type handler even if value type already matches target type to ensure all proper transforms are applied. + * Updates MediaTypeHandler to return null if no media is found rather than returning an object with all null properties (c) The Nerdery LLC 2016. All Rights Reserved. Umbraco UmbracoVault Mapping ObjectMapper ORM CMS diff --git a/appveyor.yml b/appveyor.yml index 6dcb73d..3aaae47 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: - CURRENT_VERSION: 1.3.2 -version: 1.3.2-{build} + CURRENT_VERSION: 1.3.3 +version: 1.3.3-{build} os: Visual Studio 2015 assembly_info: patch: true