flavors work with API now

This commit is contained in:
2021-12-02 14:44:48 +01:00
parent 2536c46fc7
commit 3853dbfdb9
12 changed files with 74 additions and 11 deletions
+8 -1
View File
@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
namespace zero.Pages;
namespace zero.Stores;
public class FlavorOptions
{
@@ -45,6 +45,13 @@ public class FlavorOptions
}
public bool Exists<TEntity>(string alias)
{
List<FlavorConfig> flavors = Flavors.GetValueOrDefault(typeof(TEntity), new());
return flavors.Any(x => x.Alias == alias);
}
public void Provide<TEntity>()
where TEntity : ISupportsFlavors, new()
{
+23 -1
View File
@@ -18,7 +18,29 @@ public partial class StoreOperations : IStoreOperations
return Result<T>.Fail("@errors.onsave.empty");
}
bool isUpdate = !model.Id.IsNullOrEmpty() && await Session.Advanced.ExistsAsync(model.Id);
bool isUpdate = false;
// check if the Id for a model already exists
if (!model.Id.IsNullOrEmpty())
{
bool exists = await Session.Advanced.ExistsAsync(model.Id);
if (!exists)
{
return Result<T>.Fail("@errors.onsave.noidmatch");
}
isUpdate = true;
}
// validate flavor
if (model is ISupportsFlavors flavorModel && !flavorModel.Flavor.IsNullOrEmpty())
{
if (!Flavors.Exists<T>(flavorModel.Flavor))
{
return Result<T>.Fail("@errors.onsave.flavornotfound");
}
}
// prepare model
PrepareForSave(model);