Added messages to category manager for success, failure
This commit is contained in:
parent
b1d3031333
commit
894a653cdd
|
@ -20,6 +20,12 @@
|
|||
<div class="bg-primary bg-error bg-warning bg-info bg-secondary bg-accent"></div>
|
||||
-->
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Message)) {
|
||||
<div class="alert alert-info">
|
||||
<span>@Message</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
<section class="w-full">
|
||||
<EditForm method="post" class="w-full" FormName="add-category"
|
||||
Model="Model" OnValidSubmit="AddCategory_OnValidSubmit">
|
||||
|
@ -58,12 +64,15 @@
|
|||
private InputModel Model { get; set; } = new();
|
||||
private List<Category> Categories { get; set; } = new();
|
||||
|
||||
private string Message { get; set; } = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||
Categories = await context.Set<Category>().OrderBy(c => c.Color).ToListAsync();
|
||||
}
|
||||
|
||||
private async Task AddCategory_OnValidSubmit() {
|
||||
try {
|
||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||
|
||||
var category = new Category {
|
||||
|
@ -75,6 +84,10 @@
|
|||
await context.SaveChangesAsync();
|
||||
Categories.Add(category);
|
||||
Model = new();
|
||||
Message = Localizer["Category_Success"];
|
||||
} catch {
|
||||
Message = Localizer["Category_Error"];
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InputModel {
|
||||
|
|
|
@ -131,4 +131,10 @@
|
|||
<data name="Category_Color_Secondary" xml:space="preserve">
|
||||
<value>Sekundär</value>
|
||||
</data>
|
||||
<data name="Category_Success" xml:space="preserve">
|
||||
<value>Kategorie hinzugefügt.</value>
|
||||
</data>
|
||||
<data name="Category_Error" xml:space="preserve">
|
||||
<value>Fehler beim hinzufügen der Kategorie. Kategorien müssen einzigartis sein, ungeachtet Groß-/Kleinschreibung oder Akzenten.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -131,4 +131,10 @@
|
|||
<data name="Category_Color_Primary" xml:space="preserve">
|
||||
<value>Primary</value>
|
||||
</data>
|
||||
<data name="Category_Success" xml:space="preserve">
|
||||
<value>Category added.</value>
|
||||
</data>
|
||||
<data name="Category_Error" xml:space="preserve">
|
||||
<value>Failed to add category. Categories need to be unique, ignoring case and accents.</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in a new issue