69 lines
2.5 KiB
Plaintext
69 lines
2.5 KiB
Plaintext
@inject IEntryService EntryService
|
|
|
|
<div class="dialog-backdrop" @onclick="Cancel">
|
|
<div class="dialog-content" @onclick:stopPropagation="true">
|
|
<h5>@(EditEntry != null ? "Eintrag bearbeiten" : "Neuer Eintrag")</h5>
|
|
|
|
<div class="form-container">
|
|
@if(EditEntry == null) {
|
|
<label class="form-label">Art</label>
|
|
<select @bind="entryType">
|
|
<option value="@EntryType.Income">Einnahme</option>
|
|
<option value="@EntryType.Expense">Ausgabe</option>
|
|
</select>
|
|
}
|
|
|
|
<label class="form-label">Datum</label>
|
|
<input type="date" @bind="date" />
|
|
|
|
<label class="form-label">Bezeichnung</label>
|
|
<input type="text" class="form-control" @bind="title" placeholder="Beschreibung" />
|
|
|
|
<label class="form-label">Betrag (€)</label>
|
|
<input type="number" class="form-control" @bind="amount" step="0.01" min="0.01" />
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-end gap-2">
|
|
<button class="btn btn-success" @onclick="Save"
|
|
disabled="@(string.IsNullOrWhiteSpace(title) || amount <= 0)">
|
|
<i class="bi bi-check-lg"></i> @(EditEntry != null ? "Speichern" : "Hinzufügen")
|
|
</button>
|
|
<button class="btn btn-outline-secondary" @onclick="Cancel"><i class="bi bi-x-lg"></i> Abbrechen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public int AccountId { get; set; }
|
|
[Parameter] public EntryDto? EditEntry { get; set; }
|
|
[Parameter] public EventCallback OnSave { get; set; }
|
|
[Parameter] public EventCallback OnCancel { get; set; }
|
|
|
|
private EntryType entryType = EntryType.Income;
|
|
private DateTime date = DateTime.Today;
|
|
private string title = string.Empty;
|
|
private decimal amount;
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (EditEntry != null)
|
|
{
|
|
entryType = EditEntry.Type;
|
|
date = EditEntry.Date;
|
|
title = EditEntry.Title;
|
|
amount = EditEntry.Amount;
|
|
}
|
|
}
|
|
|
|
private async Task Save()
|
|
{
|
|
if (EditEntry != null)
|
|
await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount);
|
|
else
|
|
await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount);
|
|
await OnSave.InvokeAsync();
|
|
}
|
|
|
|
private async Task Cancel() => await OnCancel.InvokeAsync();
|
|
}
|