diff --git a/CHANGELOG.md b/CHANGELOG.md index b08337b..672f9a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ -## v1.3.4 -* Updates UmbracoWebContext.GetChildren to ignore case when comparing document type alias with a VM's entity name -* Updates the Media and Entity type handlers to check for IPublishedContent before assuming the input is a string id +## v1.3.5 +* Automatically mapping media and content entities ## v1.3.3 * Updates MediaTypeHandler to return null if no media is found rather than returning an object with all null properties diff --git a/UmbracoVault/TypeHandlers/MediaTypeHandler.cs b/UmbracoVault/TypeHandlers/MediaTypeHandler.cs index 6642985..ab1945a 100644 --- a/UmbracoVault/TypeHandlers/MediaTypeHandler.cs +++ b/UmbracoVault/TypeHandlers/MediaTypeHandler.cs @@ -27,12 +27,9 @@ private static IPublishedContent Get(string stringValue) public object GetAsType(object input) { - if (input is IPublishedContent) - { - return input; - } + var mediaObject = input as IPublishedContent; + mediaObject = mediaObject ?? Get(input?.ToString()); - var mediaObject = Get(input?.ToString()); if (mediaObject == null) { return null; diff --git a/UmbracoVault/TypeHandlers/UmbracoEntityTypeHandler.cs b/UmbracoVault/TypeHandlers/UmbracoEntityTypeHandler.cs index d96d3b9..59bca8a 100644 --- a/UmbracoVault/TypeHandlers/UmbracoEntityTypeHandler.cs +++ b/UmbracoVault/TypeHandlers/UmbracoEntityTypeHandler.cs @@ -3,8 +3,11 @@ using System.Linq; using Umbraco.Core.Models; +using Umbraco.Web; using UmbracoVault.Attributes; +using UmbracoVault.Exceptions; +using UmbracoVault.Extensions; namespace UmbracoVault.TypeHandlers { @@ -13,9 +16,23 @@ public class UmbracoEntityTypeHandler : ITypeHandler { public object GetAsType(object input) { - if (input is IPublishedContent) + var publishedContent = input as IPublishedContent; + if (publishedContent != null) { - return input; + var result = typeof(T).CreateWithContentConstructor(publishedContent); + if (result == null) + { + result = typeof(T).CreateWithNoParams(); + } + + if (result == null) + { + throw new ConstructorUnavailableException(typeof(T)); + } + + Vault.Context.FillClassProperties(result, (alias, recursive) => publishedContent.GetPropertyValue(alias, recursive)); + + return result; } var content = Vault.Context.GetContentById(input.ToString()); diff --git a/UmbracoVault/UmbracoVault.nuspec b/UmbracoVault/UmbracoVault.nuspec index 08f072b..39cb8c2 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.GetChildren to ignore case when comparing document type alias with a VM's entity name - * Updates Media and Entity type handlers to check for IPublishedContent before assuming string input + * Automatically mapping media and content entities (c) The Nerdery LLC 2016. All Rights Reserved. Umbraco UmbracoVault Mapping ObjectMapper ORM CMS diff --git a/appveyor.yml b/appveyor.yml index fe2727f..c16b293 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: - CURRENT_VERSION: 1.3.4 -version: 1.3.4-{build} + CURRENT_VERSION: 1.3.5 +version: 1.3.5-{build} os: Visual Studio 2015 assembly_info: patch: true