mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
Added JSON
This commit is contained in:
@ -79,7 +79,7 @@ namespace Esiur.Stores.EntityCore
|
||||
public AsyncReply<bool> Put(IResource resource)
|
||||
{
|
||||
if (resource is EntityStore)
|
||||
return new AsyncReply<bool>(false);
|
||||
return new AsyncReply<bool>(true);
|
||||
|
||||
var type = ResourceProxy.GetBaseType(resource);//.GetType().;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
|
||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -22,6 +22,7 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
using Esiur.Core;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Permissions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -43,6 +44,9 @@ namespace Esiur.Stores.EntityCore
|
||||
//}
|
||||
|
||||
public static T AddResource<T>(this DbSet<T> dbSet, object properties = null) where T : class, IResource
|
||||
=> AddResourceAsync(dbSet, properties).Wait();
|
||||
|
||||
public static async AsyncReply<T> AddResourceAsync<T>(this DbSet<T> dbSet, object properties = null) where T : class, IResource
|
||||
{
|
||||
var store = dbSet.GetInfrastructure().GetService<IDbContextOptions>().FindExtension<EsiurExtensionOptions>().Store;
|
||||
var manager = store.Instance.Managers.FirstOrDefault();// > 0 ? store.Instance.Managers.First() : null;
|
||||
@ -51,28 +55,31 @@ namespace Esiur.Stores.EntityCore
|
||||
|
||||
//var resource = dbSet.GetInfrastructure().CreateResource<T>(properties);
|
||||
//var resource = Warehouse.New<T>("", options.Store, null, null, null, properties);
|
||||
var resource = Warehouse.New<T>("", null, null, null, null, properties);
|
||||
var resource = await Warehouse.New<T>("", null, null, null, null, properties);
|
||||
var entity = dbSet.Add(resource);
|
||||
entity.Context.SaveChanges();
|
||||
await entity.Context.SaveChangesAsync();
|
||||
|
||||
var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(resource);
|
||||
|
||||
Warehouse.Put(resource, id.ToString(), store, null, null, 0, manager);
|
||||
await Warehouse.Put(resource, id.ToString(), store, null, null, 0, manager);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static T CreateResource<T>(this IServiceProvider serviceProvider, object properties = null) where T : class, IResource
|
||||
public static async AsyncReply<T> CreateResourceAsync<T>(this IServiceProvider serviceProvider, object properties = null) where T : class, IResource
|
||||
{
|
||||
var options = serviceProvider.GetService<IDbContextOptions>().FindExtension<EsiurExtensionOptions>();
|
||||
|
||||
var resource = Warehouse.New<T>("", options.Store, null, null, null, properties);
|
||||
var resource = await Warehouse.New<T>("", options.Store, null, null, null, properties);
|
||||
|
||||
resource.Instance.Managers.AddRange(options.Store.Instance.Managers.ToArray());
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static T CreateResource<T>(this IServiceProvider serviceProvider, object properties = null) where T : class, IResource
|
||||
=> CreateResourceAsync<T>(serviceProvider, properties).Wait();
|
||||
|
||||
public static DbContextOptionsBuilder UseEsiur(this DbContextOptionsBuilder optionsBuilder,
|
||||
//DbContext context,
|
||||
string name = null,
|
||||
@ -86,7 +93,7 @@ namespace Esiur.Stores.EntityCore
|
||||
if (extension == null)
|
||||
{
|
||||
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider });
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider }).Wait();
|
||||
extension = new EsiurExtensionOptions(store);
|
||||
//store.Options = optionsBuilder;
|
||||
//store.DbContext = context;
|
||||
@ -113,7 +120,7 @@ namespace Esiur.Stores.EntityCore
|
||||
|
||||
if (extension == null)
|
||||
{
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider });
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider }).Wait();
|
||||
extension = new EsiurExtensionOptions(store);
|
||||
//store.Options = optionsBuilder;
|
||||
//store.Options = extension;
|
||||
|
@ -76,10 +76,10 @@ namespace Esiur.Stores.EntityCore
|
||||
return cache;
|
||||
|
||||
// check if the object exists
|
||||
var obj = Warehouse.New(entityType.ClrType) as EntityResource;//, "", options.Store, null, manager);
|
||||
var obj = Warehouse.New(entityType.ClrType).Wait() as EntityResource;//, "", options.Store, null, manager);
|
||||
//obj._PrimaryId = id;
|
||||
options.Store.TypesByType[entityType.ClrType].PrimaryKey.SetValue(obj, id);
|
||||
Warehouse.Put(obj, id.ToString(), options.Store, null, null, 0, manager);
|
||||
Warehouse.Put(obj, id.ToString(), options.Store, null, null, 0, manager).Wait();
|
||||
|
||||
// obj.Instance.IntVal = id;//.Variables.Add("eid", id);
|
||||
|
||||
|
Reference in New Issue
Block a user