LANCommander/LANCommander.Server/UI/Components/TaxonomyInput.razor
2025-12-06 19:28:04 -06:00

32 lines
No EOL
907 B
Text

@typeparam TTaxonomy where TTaxonomy : BaseTaxonomyModel
<TagsInput
DataSource="_entities"
OnCreateTag="Add"
Values="Values"
ValuesChanged="ValuesChanged"
OptionLabelSelector="t => t.Name" />
@code {
[Parameter] public BaseDatabaseService<TTaxonomy> DataService { get; set; }
[Parameter] public 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();
}
async Task<TTaxonomy> Add(string name)
{
var taxonomy = Activator.CreateInstance(typeof(TTaxonomy)) as TTaxonomy;
taxonomy.Name = name;
taxonomy = await DataService.AddAsync(taxonomy);
return taxonomy;
}
}