Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Additional Extensions : Custom groups #6

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/// </summary>
public static class PublishedContentExtensions
{

/// <summary>
/// Adds an extension method to IPublishedContent to determine if the content item should be shown to the current site
/// visitor, based on the personalisation groups associated with it.
Expand All @@ -23,6 +24,34 @@ public static class PublishedContentExtensions
public static bool ShowToVisitor(this IPublishedContent content, bool showIfNoGroupsDefined = true)
{
var pickedGroups = GetPickedGroups(content);
return ShowToVisitor(pickedGroups, showIfNoGroupsDefined);
}

public static bool ShowToVisitor(this UmbracoHelper umbraco, IEnumerable<int> groupIds, bool showIfNoGroupDefined = true)
{
try
{
var pickedGroups = umbraco.TypedContent(groupIds).ToList();

return ShowToVisitor(pickedGroups, showIfNoGroupDefined);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}

return false;
}

/// <summary>
/// Adds an extension method to IPublishedContent to determine if the content item should be shown to the current site
/// visitor, based on the personalisation groups associated with it.
/// </summary>
/// <param name="pickedGroups">List of IPublishedContent items that are the groups you want to check against.</param>
/// <param name="showIfNoGroupsDefined">Indicates the response to return if groups cannot be found on the content</param>
/// <returns>True if content should be shown to visitor</returns>
public static bool ShowToVisitor(IList<IPublishedContent> pickedGroups, bool showIfNoGroupsDefined = true)
{
if (!pickedGroups.Any())
{
// No personalisation groups picked or no property for picker, so we return the provided default
Expand Down