diff --git a/zero.Api/Abstractions/ZeroApiEntityStoreOperations.cs b/zero.Api/Abstractions/ZeroApiEntityStoreOperations.cs index 9479b37c..efdf8706 100644 --- a/zero.Api/Abstractions/ZeroApiEntityStoreOperations.cs +++ b/zero.Api/Abstractions/ZeroApiEntityStoreOperations.cs @@ -19,6 +19,7 @@ public class ZeroApiEntityStoreOperations { Controller = controller; Store = store; + Store.Config.IncludeInactive = true; } diff --git a/zero.Api/ConfigureApiJsonOptions.cs b/zero.Api/ConfigureApiJsonOptions.cs new file mode 100644 index 00000000..52546180 --- /dev/null +++ b/zero.Api/ConfigureApiJsonOptions.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using System.Text.Json; + +namespace zero.Api; + + +public class ConfigureApiJsonOptions : IConfigureOptions +{ + public void Configure(JsonOptions options) + { + // TODO this matches all serialization, not limited to API + options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); + } +} \ No newline at end of file diff --git a/zero.Api/Plugin.cs b/zero.Api/Plugin.cs index 091cad18..fa11d257 100644 --- a/zero.Api/Plugin.cs +++ b/zero.Api/Plugin.cs @@ -26,6 +26,8 @@ public class ZeroApiPlugin : ZeroPlugin services.AddTransient(); services.AddTransient(); + services.ConfigureOptions(); + ZeroModuleCollection modules = new(); modules.Add(); diff --git a/zero.Core/Persistence/RavenQueryableExtensions.cs b/zero.Core/Persistence/RavenQueryableExtensions.cs index f0ce3ed5..332154e4 100644 --- a/zero.Core/Persistence/RavenQueryableExtensions.cs +++ b/zero.Core/Persistence/RavenQueryableExtensions.cs @@ -71,6 +71,21 @@ public static class RavenQueryableExtensions } + public static IQueryable WhereIf(this IQueryable source, Expression> predicate, bool condition, Expression> elsePredicate = null) + { + if (!condition) + { + if (elsePredicate != null) + { + return source.Where(elsePredicate); + } + return source; + } + + return source.Where(predicate); + } + + public static IQueryable SearchIf(this IQueryable source, Expression> fieldSelector, string searchTerms, string suffix = null, string prefix = null, SearchOperator @operator = SearchOperator.Or) { if (String.IsNullOrWhiteSpace(searchTerms)) diff --git a/zero.Core/Stores/EntityStore.cs b/zero.Core/Stores/EntityStore.cs index 261077df..62ea53b5 100644 --- a/zero.Core/Stores/EntityStore.cs +++ b/zero.Core/Stores/EntityStore.cs @@ -12,9 +12,11 @@ public abstract class EntityStore : IEntityStore where T : ZeroIdEntity, I /// public IZeroDocumentSession Session => Operations.Session; + /// + public StoreConfig Config => Operations.Config; + protected IZeroContext Context { get; private set; } - protected StoreConfig Config => Operations.Config; protected IInterceptors Interceptors { get; private set; } @@ -106,6 +108,11 @@ public interface IEntityStore where T : ZeroIdEntity, ISupportsFlavors, ISupp /// IZeroDocumentSession Session { get; } + /// + /// Configure the store + /// + StoreConfig Config { get; } + /// /// Get new instance of an entity (with an optional flavor) ///