@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Setting.Tax @using Indotalent.Features.Setting.Tax.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject TaxService TaxService @inject ISnackbar Snackbar
@(ReadOnly ? "Tax Details" : "Edit Tax") @(ReadOnly ? "Viewing tax configuration." : "Modify existing tax information.")
Tax Code Percentage (%) Tax Name Category Description Audit History Created At @DateTimeExtensions.ToString(_model.CreatedAt) Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Last Updated At @DateTimeExtensions.ToString(_model.UpdatedAt) Last Updated By @(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")
@(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { Updating... } else { Save Changes } }
@code { [Parameter] public UpdateTaxRequest Data { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private UpdateTaxValidator _validator = new(); private UpdateTaxRequest _model = new(); private bool _processing = false; protected override void OnInitialized() { _model = new UpdateTaxRequest { Id = Data.Id, Code = Data.Code, Name = Data.Name, PercentageValue = Data.PercentageValue, Category = Data.Category, Description = Data.Description, CreatedAt = Data.CreatedAt, CreatedBy = Data.CreatedBy, UpdatedAt = Data.UpdatedAt, UpdatedBy = Data.UpdatedBy }; } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await TaxService.UpdateTaxAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Tax updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } catch (Exception ex) { Snackbar.Add($"Error: {ex.Message}", Severity.Error); } finally { _processing = false; } } }