Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / ExtensionMethods.cs
Last active August 29, 2015 14:07
Umbraco GetPropertyValueRecursively with custom logic to determine if a recursive value is valid
using System;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace My.Website.ExtensionMethods {
public static class UmbracoExtensions {
public static TPropertyValue GetPropertyValueRecursively<TPropertyValue>(this IPublishedContent content, string alias, Expression<Func<TPropertyValue, bool>> recursiveValueIsValidExpression, TPropertyValue defaultValue = default(TPropertyValue)) {
if (content.HasProperty(alias)) {
var value = content.GetPropertyValue<TPropertyValue>(alias);
@jamiepollock
jamiepollock / CustomDatabaseEvents.cs
Created October 21, 2014 13:35
A custom database event intended for pre-Umbraco v7.2 website using ArcheType which generates long data type prevalues.
using System;
using My.Website.ExtensionMethods;
using Umbraco.Core;
using Umbraco.Core.Persistence;
namespace My.Website.Events {
public class CustomDatabaseEvents : ApplicationEventHandler {
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
ApplyUmbracoDatabaseHotfixForLongArchetypeModels(applicationContext.DatabaseContext.Database);
}
@jamiepollock
jamiepollock / index
Last active August 29, 2015 14:19
Binary #UmbracoPeteMeme
<!doctype html>
<table align="center" cellpadding="10">
<tbody>
<tr bgcolor="BLACK">
<td>
<!-- IMAGE BEGINS HERE -->
<font size="-3">
<pre>
@jamiepollock
jamiepollock / ContactDetailsGroupBuilderTemplate.js
Last active August 29, 2015 14:21
JavaScript to get the number of enabled fieldsets from a nested archtype
var ContactDetailsGroupBuilderTemplate = {};
ContactDetailsGroupBuilderTemplate.Helpers = {};
ContactDetailsGroupBuilderTemplate.Helpers.getNumberOfEnabledFieldsets = function (fieldsets) {
return fieldsets.filter(function (v) {
return v.disabled === false;
}).length;
}
@jamiepollock
jamiepollock / BasicPageViewModel.cs
Last active August 29, 2015 14:22
Gist using Umbraco Ditto and nested POCOs. Note: pre-rev4 this code worked with Ditto v.6 but not v.7.
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
namespace My.Website.ViewModels {
public class BasicPageViewModel {
public BasicPageViewModel(IPublishedContent content) {
Seo = content.As<SeoViewModel>();
}
[DittoIgnore]
@jamiepollock
jamiepollock / HomeViewModel.cs
Created June 15, 2015 15:35
The following is an implementation of the GridResolver. The attribute takes two properties; propertyAlias and framework. Framework is used to determine the grid framework. In this case it is fanoe (based on the v7.2.x+ starter kit.
using System.Web.Mvc;
using Our.Umbraco.Ditto.Resolvers.Grid.Attributes;
namespace My.Website.ViewModels {
public class HomeViewModel {
[GridResolver(framework: "fanoe")]
public MvcHtmlString Content { get; set; }
}
}
@jamiepollock
jamiepollock / RebuildMediaCacheTool.ascx
Created June 18, 2015 16:08
Tool for automatically resaving media nodes in Umbraco v6. Add to your dashboard.config to gain easy access to this tool.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RebuildMediaCacheTool.ascx.cs" Inherits="My.Website.Dashboard.RebuildMediaCacheTool" %>
<div class="dashboardWrapper">
<h2>Rebuild Media Cache</h2>
<img src="/umbraco_client/Dashboards/ExamineManagementIco.png" alt="" class="dashboardIcon" />
<asp:MultiView ID="MainView" runat="server">
<asp:View ID="InitialView" runat="server">
<asp:Button ID="RebuildButton" Text="Rebuild Media Cache" runat="server"/>
</asp:View>
<asp:View ID="CompleteView" runat="server">
<p>Rebuild complete!</p>
@jamiepollock
jamiepollock / MultipleIPublishedTypeConverterBase.cs
Last active September 22, 2015 07:59
Ditto TypeConverter - Multiple IEnumerable<IPublishedContent> & Single IPublishedContent
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace My.Website.ComponentModel.TypeConverters
{
public abstract class MultipleIPublishedContentTypeConverterBase<T> : TypeConverter
@jamiepollock
jamiepollock / CustomDittoValueResolver.cs
Created September 21, 2015 14:58
Custom Ditto ValueResolver - Single IPublishedContent from IEnumerable<IPublishedContent
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
namespace My.Website.ComponentModel
{
public class SinglePublishedContentUmbracoPropertyAttribute : UmbracoPropertyAttribute
@jamiepollock
jamiepollock / JsonDropDownListApiController.cs
Created November 27, 2013 22:19
A demo Umbraco v6+ UmbracoApiController (an Umbraco Context wrapped WebApiController). Each request returns an array of strings which would typically be read in by a JavaScript library as JSON.
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
namespace UmbracoDemo.Controllers
{
[PluginController("JsonDropDownList")]
public class JsonDropDownListApiController : UmbracoApiController