Skip to content

Commit

Permalink
Merge pull request #40 from kluhman/master
Browse files Browse the repository at this point in the history
updated MediaTypeHandler to return null if no media is found
  • Loading branch information
kluhman authored Feb 2, 2017
2 parents 6e8c325 + b68179d commit 8088e19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 14 additions & 7 deletions UmbracoVault/TypeHandlers/MediaTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(object input)
{
var result = typeof(T).CreateWithNoParams<T>();
{
var mediaObject = Get(input?.ToString());
if (mediaObject == null)
{
return null;
}

var result = typeof(T).CreateWithNoParams<T>();
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;
}

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.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
</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.2
version: 1.3.2-{build}
CURRENT_VERSION: 1.3.3
version: 1.3.3-{build}
os: Visual Studio 2015
assembly_info:
patch: true
Expand Down

0 comments on commit 8088e19

Please sign in to comment.