Finished converter plugin
This commit is contained in:
@@ -7,4 +7,5 @@ public interface IContextExplorer {
|
||||
public TableConfig? GetTable(string tableDisplayName);
|
||||
public TableConfig? GetTable(Type tableEntity);
|
||||
public ITableManager? GetTableManager(string tablePropertyName);
|
||||
public ITableManager? GetTableManager(Type tableType);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public interface ITableManager {
|
||||
public Task EditItem(object item);
|
||||
public Task AddItem(object item);
|
||||
public Task AddAll(IEnumerable<object> items);
|
||||
public Task RevertChanges(object item);
|
||||
public Task<object?> GetOne(object key);
|
||||
|
||||
public Task<string> DisplayProperty(object? item, PropertyConfig prop, object? value = null, object? enumerableValue = null);
|
||||
}
|
||||
@@ -55,6 +55,21 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITableManager? GetTableManager(Type tableType) {
|
||||
foreach (var context in config.Contexts) {
|
||||
var table = context.Tables.FirstOrDefault(table => table.TableType == tableType);
|
||||
if (table is null) continue;
|
||||
|
||||
var dbContext = provider.GetService(context.ContextType) as DbContext;
|
||||
if (dbContext is null) return null;
|
||||
|
||||
var type = typeof(TableManager<>).MakeGenericType(table.TableType);
|
||||
return Activator.CreateInstance(type, dbContext, table, this, provider) as ITableManager;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SeedTableData(TableConfig table) {
|
||||
if (table.Seeded) return;
|
||||
var dbContext = (provider.GetRequiredService(table.ContextConfig.ContextType) as DbContext)!;
|
||||
|
||||
@@ -55,6 +55,11 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<object?> GetOne(object key) {
|
||||
var table = context.Set<TModel>();
|
||||
return await table.FindAsync(key);
|
||||
}
|
||||
|
||||
public async Task RevertChanges(object item) {
|
||||
var entry = context.Entry((TModel)item);
|
||||
await entry.ReloadAsync();
|
||||
|
||||
Reference in New Issue
Block a user