Skip to content

Instantly share code, notes, and snippets.

@davidknipe
davidknipe / AddMetaClass.cs
Created March 5, 2015 10:52
Create an EPiServer Commerce Metafield programmatically and add it to a Metaclass in Business Foundation
/// <summary>
/// Programmatically create a new MetaField on the Contact MetaClass <seealso href="http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Business-Foundation/Business-Meta-Model/MetaField-class/"/>
/// </summary>
private void setupMetaField()
{
MetaClassManager metaModel = DataContext.Current.MetaModel;
foreach (MetaClass mc in metaModel.MetaClasses)
{
if (mc.Name == "Contact")
{
@davidknipe
davidknipe / PriceEventListenerInit.cs
Last active August 29, 2015 14:15
Example PriceEvent listener for the PriceEvents for EPiServer Commerce
[InitializableModule]
[ModuleDependency( typeof(EPiServer.Web. InitializationModule))]
public class PriceEventListenerInit : IInitializableModule
{
public void Initialize( InitializationEngine context)
{
var priceEvents = ServiceLocator.Current.GetInstance<IPriceEvents>();
priceEvents.PriceChanged += contentEvents_PriceChanged;
}
@davidknipe
davidknipe / Index.cshtml
Last active August 29, 2015 14:15
Claims helper block
@model ListAllClaimsModel
<div>
<h3>@Model.BlockTitle</h3>
<table class="table table-striped table-condensed">
@*<thead>
<tr>
<th>Claims</th>
</tr>
@davidknipe
davidknipe / Example-Auth0-rule.js
Created February 15, 2015 21:35
Example Auth0 rule
function (user, context, callback) {
user.roles = [];
if (user.name.indexOf('Jones') > -1)
{
user.roles.push('WebAdmins');
user.roles.push('WebEditors');
}
// all users are member of public
@davidknipe
davidknipe / Auth0SynchronizingUserService.cs
Created February 15, 2015 21:23
Custom SynchronizingUserService implementation for Auth0 when using EPiServer
public class Auth0SynchronizingUserService : SynchronizingUserService
{
public override Task SynchronizeAsync(ClaimsIdentity identity)
{
//Transform the passed http:/schemas.auth0.com/roles claims to System.Security.Claims
foreach (var claim in identity.Claims)
{
if (claim.Type == "http://schemas.auth0.com/roles")
{
identity.AddClaim(new Claim(ClaimTypes.Role, claim.Value));
@davidknipe
davidknipe / EPiServer-Powerslice-Example-Slices.cs
Last active August 29, 2015 14:15
EPiServer Powerslice example slides
[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
public class PagesSlice : ContentSliceBase<StandardPage>
{
public override string Name
{
get { return "Pages"; }
}
}
[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]