Skip to content

Instantly share code, notes, and snippets.

View naepalm's full-sized avatar

Janae Cram naepalm

View GitHub Profile
@naepalm
naepalm / GridExtensions.cs
Last active July 20, 2017 15:48
Grid extensions for use with Ditto, Skybrud, DocType Grid Editor, and the DocType Grid Editor Reusable Content package
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Our.Umbraco.Ditto;
using Offroadcode.Web.Models.Widgets;
using Skybrud.Umbraco.GridData;
using Skybrud.Umbraco.GridData.Values;
using Umbraco.Core.Models;
using Umbraco.Web;
@naepalm
naepalm / ExampleCode.cshtml
Last active August 3, 2017 16:35
The handy CheckboxListFor Html extension.
@using(Html.BeginUmbracoForm<ExampleSurfaceController>("SubmitForm", FormMethod.Post))
{
@Html.CheckBoxListFor(x => x.CheckboxListField, Model.CheckboxListSelectItems)
<button type="submit">Submit</button>
}
@naepalm
naepalm / Helpers.js
Last active August 3, 2017 22:46
Helper functions for react, such as price currency formatting.
var Helpers = {
/**
* @function formatMoney
* @param {number} n - The number to be formatted
* @param {string} d - The character to be used for the decimal. Defaults to ".".
* @param {string} t - the character to be used for the thousands separator. Defaults to ",".
* @param {int} c - the number of decimal places. Defaults to 2.
* @returns {string}
* @description Formats a number to a price
*/
@naepalm
naepalm / Editors\Base.cshtml
Last active October 30, 2017 20:20
Grid view & controls for Skybrud's strongly typed models with Responsive BP
@model GridControl
@using Grid.Web
@using Skybrud.Umbraco.GridData
@try
{
<text>@Html.Partial(Model.EditorView(), Model)</text>
}
catch (Exception ex) {
<pre>@ex.ToString()</pre>
@naepalm
naepalm / DictionaryController.cs
Created February 8, 2017 18:08
Get all dictionary items for a language on a site and spit them out in an API Controller.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Web;
using Umbraco.Web.WebApi;
namespace Olympic.Web.Controllers.Api
{
public class DictionaryController : UmbracoApiController
{
@naepalm
naepalm / HasGridRow.cs
Last active July 20, 2018 15:06
Checks to see if a grid has a specific row.
public static bool HasGridRow(this GridDataModel model, string rowName)
{
if (model.Sections.Any())
{
foreach (var section in model.Sections)
{
if (section.HasRows)
{
foreach (var row in section.Rows)
{
@naepalm
naepalm / RadioButtonValueConverter.cs
Created August 31, 2018 15:30
Converts the core radio button automagically with ModelsBuilder from the value Id to the prevalue string. This does not use Dependency Injection, but it does work, so feel free to use it if you'd like!
using System;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
namespace Offroadcode.Web.PropertyConverters
{
class RadioButtonValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
{
@naepalm
naepalm / MarkdownConverter.gs
Created January 8, 2019 18:19
Converts a Google Doc into Markdown and e-mails it to the account attached to the document. Open a doc and go to Tools > Script Editor then paste this code in and run it.
/*
Usage:
Adding this script to your doc:
- Tools > Script Manager > New
- Select "Blank Project", then paste this code in and save.
Running the script:
- Tools > Script Manager
- Select "ConvertToMarkdown" function.
- Click Run button.
- Converted doc will be mailed to you. Subject will be "[MARKDOWN_MAKER]...".
@naepalm
naepalm / ContentExtensions.cs
Last active January 10, 2019 01:32
A set of useful extension methods for Umbraco properties.
namespace Client.Web
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models;
using Newtonsoft.Json;
using Umbraco.Core.Models;

How to set up ModelsBuilder & AutoMapper on a Project

AutoMapper is used to map the ModelsBuilder Api to Umbraco ViewModels. Dave Woestenborghs has written an excellent article on 24 Days that you can read for more information. This step-by-step is basically a paired down version of his article and a heads up for gotchas we encountered when setting up our project.

Step 1: Install the Visual Studio Extension for ModelsBuilder

(If this isn't your first project using this method, you already have this installed, so don't worry about it!)

Download and Install Stephan's custom ModelsBuilder tool for VS: