Skip to content

Commit

Permalink
uComponents#127 fleshed out helper method - uQuery database call no l…
Browse files Browse the repository at this point in the history
…onger made
  • Loading branch information
Hendy committed Feb 6, 2016
1 parent 1ca5d61 commit eb9ca7d
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions source/nuPickers/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Web;
using System.Web.Hosting;
using umbraco;
using Umbraco.Web;

internal static class Helper
{
Expand Down Expand Up @@ -129,16 +130,47 @@ internal static string GetDataFromUrl(string url)
}

/// <summary>
/// replacement for built-in uQuery method (as that hits the database)
/// temp replacement for built-in uQuery method (as that hits the database)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <param name="id">the id of a content, media or member item</param>
/// <returns>an enum instance of the UmbracoObjectType</returns>
internal static uQuery.UmbracoObjectType GetUmbracoObjectType(int id)
{
// TODO:
// return variable
uQuery.UmbracoObjectType umbracoObjectType = uQuery.UmbracoObjectType.Unknown;

// HACK: returning uQuery call, to prevent breaking
return uQuery.GetUmbracoObjectType(id);
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);

// attempt to get content
if (umbracoHelper.TypedContent(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Document;
}
else
{
// attempt to get media
if(umbracoHelper.TypedMedia(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Media;
}
else
{
// attempt to get member
try
{
if (umbracoHelper.TypedMember(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Member;
}
}
catch
{
// HACK: suppress Umbraco error
}
}
}

return umbracoObjectType;
}
}
}

0 comments on commit eb9ca7d

Please sign in to comment.