Skip to content

Commit

Permalink
Merge pull request #291 from Lombiq/issue/LMBQ-399
Browse files Browse the repository at this point in the history
LMBQ-399: Adding WhenContentTypeCreate method
  • Loading branch information
DemeSzabolcs authored Oct 14, 2024
2 parents b427098 + 1a06d3f commit 3b20f92
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ public ResourceFilter WhenContentType(params string[] contentTypes) =>
public ResourceFilter WhenContentTypeEditor(params string[] contentTypes) =>
WhenContentTypeInner("Edit", contentTypes);

/// <summary>
/// Adds a filter that matches any of the provided <paramref name="contentTypes"/> to the list of
/// <see cref="ResourceFilters"/> and it is currently Create display mode.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="contentTypes"/> has no provided items.
/// </exception>
public ResourceFilter WhenContentTypeCreate(params string[] contentTypes)
{
if (contentTypes.Length == 0)
{
throw new ArgumentOutOfRangeException(
nameof(contentTypes),
$"{nameof(contentTypes)} must have at least 1 item.");
}

return When(context =>
{
var routeValues = context
.Request
.RouteValues
.ToDictionary(pair => pair.Key, pair => pair.Value?.ToString(), StringComparer.OrdinalIgnoreCase);
return routeValues.GetMaybe("action") == "Create" && contentTypes.Contains(routeValues.GetMaybe("id"));
});
}

/// <summary>
/// Adds an always matching filter to the list of <see cref="ResourceFilters"/>.
/// </summary>
Expand Down

0 comments on commit 3b20f92

Please sign in to comment.