@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Utilities.BookingManager @using Indotalent.Features.Utilities.BookingManager.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject BookingManagerService BookingManagerService @inject ISnackbar Snackbar
@(ReadOnly ? "Booking Details" : "Edit Booking") @(ReadOnly ? "Viewing booking specification." : "Modify existing booking information.")
@if (_isDataLoading) {
} else { Subject Start Date Start Time End Date End Time Booking Resource @foreach (var item in _lookupData.Resources) { @item.Name } Status @foreach (var item in _lookupData.Statuses) { @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 UpdateBookingRequest 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 UpdateBookingValidator _validator = new(); private UpdateBookingRequest _model = new(); private LookupBookingDataResponse _lookupData = new(); private bool _processing = false; private bool _isDataLoading = true; private DateTime? _startDate; private TimeSpan? _startTime; private DateTime? _endDate; private TimeSpan? _endTime; protected override async Task OnInitializedAsync() { _isDataLoading = true; try { var response = await BookingManagerService.GetLookupDataAsync(); if (response != null && response.IsSuccess) { _lookupData = response.Value!; } _model = new UpdateBookingRequest { Id = Data.Id, Subject = Data.Subject, StartTime = Data.StartTime, EndTime = Data.EndTime, StartTimezone = Data.StartTimezone, EndTimezone = Data.EndTimezone, Location = Data.Location, Description = Data.Description, IsAllDay = Data.IsAllDay, IsReadOnly = Data.IsReadOnly, IsBlock = Data.IsBlock, RecurrenceRule = Data.RecurrenceRule, Status = Data.Status, BookingResourceId = Data.BookingResourceId, CreatedAt = Data.CreatedAt, CreatedBy = Data.CreatedBy, UpdatedAt = Data.UpdatedAt, UpdatedBy = Data.UpdatedBy }; if (_model.StartTime.HasValue) { _startDate = _model.StartTime.Value.Date; _startTime = _model.StartTime.Value.TimeOfDay; } if (_model.EndTime.HasValue) { _endDate = _model.EndTime.Value.Date; _endTime = _model.EndTime.Value.TimeOfDay; } } finally { _isDataLoading = false; } } private async Task Submit() { if (ReadOnly) return; if (_startDate.HasValue && _startTime.HasValue) { _model.StartTime = _startDate.Value.Date.Add(_startTime.Value); } if (_endDate.HasValue && _endTime.HasValue) { _model.EndTime = _endDate.Value.Date.Add(_endTime.Value); } await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await BookingManagerService.UpdateBookingAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Booking updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } catch (Exception ex) { Snackbar.Add($"Error: {ex.Message}", Severity.Error); } finally { _processing = false; } } }