Guest User

Untitled

a guest
Jan 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using umbraco.cms.businesslogic.member;
  7. using Umbraco.Core;
  8. using Umbraco.Web.Routing;
  9.  
  10. namespace MyExampleSite.BusinessLogic
  11. {
  12. public class MemberProfileContentFinder : IContentFinder
  13. {
  14. public bool TryFindContent(PublishedContentRequest contentRequest)
  15. {
  16. var urlParts = contentRequest.Uri.GetAbsolutePathDecoded().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
  17.  
  18. //Check if the Url Parts
  19. // Starts with /member/*
  20. if (urlParts.Length > 1 && urlParts[0].ToLower() == "member")
  21. {
  22. //Lets try & find the member
  23. var memberName = urlParts[1];
  24.  
  25. //Try and find a member where the property matches the memberName
  26. var tryFindMember = Member.GetAll.SingleOrDefault(x => x.getProperty("profileURL").Value.ToString() == memberName);
  27.  
  28. //See if tryFindMember is not null
  29. if (tryFindMember != null)
  30. {
  31. //Need to set the member ID or pass member object to published content
  32.  
  33.  
  34. //Set the Published Content Node to be the /Profile node - can get properties off it & my member profile in the view
  35. contentRequest.PublishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute("/profile");
  36. }
  37. else
  38. {
  39. //Need to throw some custom: Not found Member
  40. //as opposed to filitering down to other iContentFinders and show the 404
  41. }
  42.  
  43.  
  44. //Return true to say found something & stop pipleine & other contentFinder's from running
  45. return true;
  46. }
  47.  
  48. //Not found any content node to display/match - so run next ContentFinder in Pipeline
  49. return false;
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment