Skip to content

Commit

Permalink
automatically mapping IPublishedContent to models
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaleb Luhman committed Jun 8, 2017
1 parent 624159b commit d6ebcfa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 2 additions & 5 deletions UmbracoVault/TypeHandlers/MediaTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ private static IPublishedContent Get(string stringValue)

public object GetAsType<T>(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;
Expand Down
21 changes: 19 additions & 2 deletions UmbracoVault/TypeHandlers/UmbracoEntityTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -13,9 +16,23 @@ public class UmbracoEntityTypeHandler : ITypeHandler
{
public object GetAsType<T>(object input)
{
if (input is IPublishedContent)
var publishedContent = input as IPublishedContent;
if (publishedContent != null)
{
return input;
var result = typeof(T).CreateWithContentConstructor<T>(publishedContent);
if (result == null)
{
result = typeof(T).CreateWithNoParams<T>();
}

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<T>(input.ToString());
Expand Down
3 changes: 1 addition & 2 deletions UmbracoVault/UmbracoVault.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<description>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).</description>
<summary>Vault for Umbraco is an easy-to-use, extensible ORM to quickly and easily get strongly-typed Umbraco CMS data into your views.</summary>
<releaseNotes>
* 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
</releaseNotes>
<copyright>(c) The Nerdery LLC 2016. All Rights Reserved.</copyright>
<tags>Umbraco UmbracoVault Mapping ObjectMapper ORM CMS</tags>
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d6ebcfa

Please sign in to comment.