flavors work with API now
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user