@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Utilities.BookingResource @using Indotalent.Features.Utilities.BookingResource.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject BookingResourceService BookingResourceService @inject ISnackbar Snackbar @(ReadOnly ? "Booking Resource Details" : "Edit Booking Resource") @(ReadOnly ? "Viewing booking resource specification." : "Modify existing resource information.") @if (_isDataLoading) { } else { Resource Name Booking Group @foreach (var item in _lookupData.BookingGroups) { @item.Name } 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 UpdateBookingResourceRequest 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 UpdateBookingResourceValidator _validator = new(); private UpdateBookingResourceRequest _model = new(); private LookupBookingGroupResponse _lookupData = new(); private bool _processing = false; private bool _isDataLoading = true; protected override async Task OnInitializedAsync() { _isDataLoading = true; try { var response = await BookingResourceService.GetBookingGroupLookupAsync(); if (response != null && response.IsSuccess) { _lookupData = response.Value!; } _model = new UpdateBookingResourceRequest { Id = Data.Id, Name = Data.Name, Description = Data.Description, BookingGroupId = Data.BookingGroupId, CreatedAt = Data.CreatedAt, CreatedBy = Data.CreatedBy, UpdatedAt = Data.UpdatedAt, UpdatedBy = Data.UpdatedBy }; } finally { _isDataLoading = false; } } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await BookingResourceService.UpdateBookingResourceAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Booking resource updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } catch (Exception ex) { Snackbar.Add($"Error: {ex.Message}", Severity.Error); } finally { _processing = false; } } }