Forked from warrenbuckley/MemberProfileContentFinder.cs
Last active
August 29, 2015 14:26
-
-
Save DavidVeksler/89b7f5a3e3c04cd37b62 to your computer and use it in GitHub Desktop.
Update for Umbraco 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Umbraco.Core; | |
using Umbraco.Core.Models; | |
using Umbraco.Core.Persistence.Querying; | |
using Umbraco.Web.Routing; | |
namespace FEE.Domain.MemberProfile | |
{ | |
// From http://creativewebspecialist.co.uk/2013/12/03/using-umbraco-pipeline-for-member-profile-urls/ | |
public class MemberProfileContentFinder : IContentFinder | |
{ | |
public bool TryFindContent(PublishedContentRequest contentRequest) | |
{ | |
var urlParts = contentRequest.Uri.GetAbsolutePathDecoded() | |
.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); | |
//Check if the Url Parts | |
// Starts with /profile/* | |
if (urlParts.Length > 1 && urlParts[0].ToLower() == "profile") | |
{ | |
//Lets try & find the member | |
var memberName = urlParts[1]; | |
//Try and find a member where the property matches the memberName | |
List<IMember> tryFindMember = | |
ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue("umbracoUrlName", | |
memberName).ToList(); | |
if (!tryFindMember.Any()) // try a partial match just in case | |
{ | |
tryFindMember = ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue("umbracoUrlName", | |
memberName,StringPropertyMatchType.Contains).ToList(); | |
} | |
//See if tryFindMember is not null | |
if (tryFindMember.Any()) | |
{ | |
//Need to set the member ID or pass member object to published content | |
HttpContext.Current.Items["memberProfile"] = tryFindMember.FirstOrDefault(); | |
//Set the Published Content Node to be the /Profile node - can get properties off it & my member profile in the view | |
contentRequest.PublishedContent = | |
contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute("/people/member-profile"); | |
} | |
//Return true to say found something & stop pipeline & other contentFinder's from running | |
return true; | |
} | |
//Not found any content node to display/match - so run next ContentFinder in Pipeline | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment