Skip to content

Instantly share code, notes, and snippets.

View nul800sebastiaan's full-sized avatar
🔥

Sebastiaan Janssen nul800sebastiaan

🔥
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
namespace Umbraco.Course.Models
{
@nul800sebastiaan
nul800sebastiaan / gist:db84218fcf07276416ed
Last active August 29, 2015 14:10
Add custom webapi route
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core;
namespace MyNamespace
{
public class MyApplicationEventHandler : ApplicationEventHandler
{
public class Stream : RenderModel
{
public Stream(IPublishedContent content, CultureInfo culture)
: base(content, culture) {}
public int Page { get; set; }
public int TotalPages { get; set; }
public int PreviousPage { get; set; }
public int NextPage { get; set; }
public bool IsFirstPage { get; set; }
public bool IsLastPage { get; set; }
entityResource.getById(1120, "Content").then(
function(ent) {
$scope.nodeUrl = ent.urls[0];
}
);
// Get the type by type alias (aka. document type alias)
var type = Services.ContentTypeService.GetContentType("statusUpdate");
// Get the 10 latest nodes (based on create date) of the type from the "type"-object
// and create a list of StatusUpdates
var statusUpdates = Services.ContentService
.GetContentOfContentType(type.Id).OrderByDescending(x => x.CreateDate).Take(10);
var content = new List<StatusUpdate>();
foreach (var statusUpdate in statusUpdates)
{
// If the memberId is 0, then the posted was made when anonymous posts were still
@nul800sebastiaan
nul800sebastiaan / TicketOrderModel.cs
Last active August 29, 2015 14:15
TicketOrderModel.cs
using System.ComponentModel.DataAnnotations;
namespace Awesome.FormDemo.Models
{
public class TicketOrderModel
{
public TicketOrderModel()
{
StepIndex = 0;
PersonalInfoStep = new PersonalInfoStep();
@nul800sebastiaan
nul800sebastiaan / gist:ca61d2eccc3faa4f6ba5
Last active August 29, 2015 14:22
Update through ContentService
using System.Configuration;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using Umbraco.Web.UI.Umbraco.Controls;
namespace My.Controllers
{
public class MyUpdateController : SurfaceController
{
public ActionResult Create(SomeModel model)
var contentService = UmbracoContext.Application.Services.ContentService;
var content = contentService.GetById(Model.Content.Id);
var currentValue = content.GetValue<bool>("myProp");
content.SetValue("myProp", !currentValue);
contentService.SaveAndPublishWithStatus(content);
@nul800sebastiaan
nul800sebastiaan / gist:b580faf76258a414df5a
Created July 28, 2015 08:51
Powershell: Remove first character of each file in directory
dir | Rename-Item -NewName { $_.Name.Substring(1, $_.Name.Length - 1) }
@nul800sebastiaan
nul800sebastiaan / Umbraco RSS feed example
Created April 20, 2011 14:58
Replace "//Article" with the nodeTypeAlias of which you want to create RSS items. Note that the "bodyText" property alias is being used for the article content.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
exclude-result-prefixes="msxml umbraco.library">