Finished converter plugin

This commit is contained in:
2025-02-28 12:15:32 +01:00
parent 6c42008a28
commit 86ace64618
14 changed files with 231 additions and 90 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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)!;

View File

@@ -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();