mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Squidex.Domain.Apps.Entities
|
|
{
|
|
public static class ContextExtensions
|
|
{
|
|
private const string HeaderNoTotal = "X-NoTotal";
|
|
|
|
public static bool ShouldSkipTotal(this Context context)
|
|
{
|
|
return context.Headers.ContainsKey(HeaderNoTotal);
|
|
}
|
|
|
|
public static ICloneBuilder WithoutTotal(this ICloneBuilder builder, bool value = true)
|
|
{
|
|
return builder.WithBoolean(HeaderNoTotal, value);
|
|
}
|
|
|
|
public static ICloneBuilder WithBoolean(this ICloneBuilder builder, string key, bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
builder.SetHeader(key, "1");
|
|
}
|
|
else
|
|
{
|
|
builder.Remove(key);
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static ICloneBuilder WithStrings(this ICloneBuilder builder, string key, IEnumerable<string>? values)
|
|
{
|
|
if (values?.Any() == true)
|
|
{
|
|
builder.SetHeader(key, string.Join(",", values));
|
|
}
|
|
else
|
|
{
|
|
builder.Remove(key);
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
}
|
|
}
|
|
|