LANCommander/LANCommander.Server/UI/Components/TaxonomyInput.razor
Aaron Powell 5b0368bf7a Changing how null is detected and handled
Using the required keyword to indicate what is expected to be passed to the components in the stack.

Looking through the usage, only the Values property can come through as null, everything else is set to something that should never be nullable (and then, if it is, it should be considered a proper error to resolve).
2025-12-17 14:50:05 +11:00

35 lines
No EOL
1 KiB
Text

@typeparam TTaxonomy where TTaxonomy : BaseTaxonomyModel
<TagsInput
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();
}
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);
return taxonomy;
}
}