LANCommander/LANCommander.Server/UI/Components/TaxonomyInput.razor

35 lines
1 KiB
Text
Raw Permalink Normal View History

@typeparam TTaxonomy where TTaxonomy : BaseTaxonomyModel
<TagsInput
2025-12-06 19:28:04 -06:00
DataSource="_entities"
OnCreateTag="Add"
Values="Values"
ValuesChanged="ValuesChanged"
OptionLabelSelector="t => t.Name" />
@code {
[Parameter] public required BaseDatabaseService<TTaxonomy> DataService { get; set; }
[Parameter] public required ICollection<TTaxonomy>? Values { get; set; }
[Parameter] public EventCallback<ICollection<TTaxonomy>> ValuesChanged { get; set; }
ICollection<TTaxonomy> _entities = new List<TTaxonomy>();
protected override async Task OnInitializedAsync()
{
_entities = await DataService.AsNoTracking().GetAsync();
}
2025-12-06 19:28:04 -06:00
async Task<TTaxonomy> Add(string name)
{
var taxonomy = (TTaxonomy?)Activator.CreateInstance(typeof(TTaxonomy));
if (taxonomy == null)
throw new InvalidOperationException($"Could not create instance of type {nameof(TTaxonomy)}");
taxonomy.Name = name;
taxonomy = await DataService.AddAsync(taxonomy);
2025-12-06 19:28:04 -06:00
return taxonomy;
}
}