@using Indotalent.Features.Organization.Employee @using Indotalent.Features.Organization.Employee.Cqrs @using MudBlazor @inject EmployeeService EmployeeService @inject ISnackbar Snackbar Edit Employee Income @if (_isLoading) {
Fetching Details...
} else {
UPDATE INCOME DETAILS
}
Cancel @if (_processing) { Updating... } else { Update Changes }
@code { [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!; [Parameter] public string Id { get; set; } = string.Empty; private MudForm? _form; private UpdateEmployeeIncomeRequest _model = new(); private string _incomeName = string.Empty; private bool _isLoading = true; private bool _processing = false; protected override async Task OnInitializedAsync() { await LoadData(); } private async Task LoadData() { _isLoading = true; var response = await EmployeeService.GetEmployeeIncomeByIdAsync(Id); if (response?.IsSuccess == true && response.Value != null) { var data = response.Value; _model.Id = data.Id; _model.IncomeId = data.IncomeId; _model.Amount = data.Amount; _model.Description = data.Description; _model.IsActive = data.IsActive; _incomeName = data.IncomeName; } _isLoading = false; } private async Task Submit() { await _form!.Validate(); if (!_form.IsValid) return; _processing = true; try { var res = await EmployeeService.UpdateEmployeeIncomeAsync(_model); await Task.Delay(500); if (res?.IsSuccess == true) { Snackbar.Add("Income updated successfully", Severity.Success); MudDialog.Close(DialogResult.Ok(true)); } } finally { _processing = false; } } private void Cancel() => MudDialog.Cancel(); }