-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
AliasPartContentHandleProvider.cs
38 lines (30 loc) · 1.24 KB
/
AliasPartContentHandleProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using OrchardCore.Alias.Indexes;
using OrchardCore.ContentManagement;
using YesSql;
namespace OrchardCore.Alias.Services;
public class AliasPartContentHandleProvider : IContentHandleProvider
{
private readonly ISession _session;
public AliasPartContentHandleProvider(ISession session)
{
_session = session;
}
public int Order => 100;
public async Task<string> GetContentItemIdAsync(string handle)
{
if (handle.StartsWith("alias:", StringComparison.OrdinalIgnoreCase))
{
handle = handle[6..];
var aliasPartIndex = await AliasPartContentHandleHelper.QueryAliasIndex(_session, handle);
return aliasPartIndex?.ContentItemId;
}
return null;
}
}
internal sealed class AliasPartContentHandleHelper
{
#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
internal static Task<ContentItem> QueryAliasIndex(ISession session, string alias) =>
session.Query<ContentItem, AliasPartIndex>(x => x.Alias == alias.ToLowerInvariant()).FirstOrDefaultAsync();
#pragma warning restore CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
}