Added entry saving support
This commit is contained in:
@@ -11,8 +11,11 @@ public class PropertyConfig(PropertyInfo info) {
|
||||
public bool Searchable { get; set; } = true;
|
||||
public PropertyInfo? DisplayedProperty { get; set; }
|
||||
public Func<object, string>? Formatter { get; set; }
|
||||
public Func<string, object>? Parser { get; set; }
|
||||
public Func<object>? Template { get; set; }
|
||||
public bool Editable { get; set; } = true;
|
||||
public bool Creatable { get; set; } = true;
|
||||
public bool DisplayValue { get; set; } = true;
|
||||
}
|
||||
|
||||
public class PropertyConfig<TProp>(PropertyConfig config) {
|
||||
@@ -22,8 +25,8 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyConfig<TProp> List(bool display) {
|
||||
config.List = display;
|
||||
public PropertyConfig<TProp> List(bool list) {
|
||||
config.List = list;
|
||||
config.Searchable = false;
|
||||
return this;
|
||||
}
|
||||
@@ -48,6 +51,16 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyConfig<TProp> ValueParser(Func<string, TProp> parser) {
|
||||
config.Parser = str => parser.Invoke(str)!;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyConfig<TProp> ValueTemplate(Func<TProp> template) {
|
||||
config.Template = () => template.Invoke()!;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyConfig<TProp> Editable(bool editable) {
|
||||
config.Editable = editable;
|
||||
return this;
|
||||
@@ -57,5 +70,10 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
|
||||
config.Creatable = creatable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyConfig<TProp> DisplayValue(bool display) {
|
||||
config.DisplayValue = display;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ public interface ITableManager {
|
||||
public (IEnumerable<object>, int) Search(string searchTerm, int page = 0, int perPage = 20);
|
||||
public int TotalPages(int perPage = 20);
|
||||
public Task DeleteItem(object item);
|
||||
public Task EditItem(object item);
|
||||
public Task AddItem(object item);
|
||||
public Task RevertChanges(object item);
|
||||
|
||||
public string DisplayProperty(object? item, PropertyInfo info, TableConfig? tableConfig);
|
||||
}
|
||||
@@ -37,6 +37,20 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task EditItem(object item) {
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task AddItem(object item) {
|
||||
var table = context.Set<TModel>();
|
||||
await table.AddAsync((TModel)item);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RevertChanges(object item) {
|
||||
await context.Entry((TModel)item).ReloadAsync();
|
||||
}
|
||||
|
||||
private bool ItemSearched(TModel item, string searchTerm) {
|
||||
foreach (var property in config.Properties) {
|
||||
if (!property.Searchable) continue;
|
||||
|
||||
Reference in New Issue
Block a user