@using Indotalent.Features.Utilities.BookingManager @using Indotalent.Features.Utilities.BookingManager.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject BookingManagerService BookingManagerService @inject ISnackbar Snackbar Add New Booking Schedule a new resource booking. 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 Cancel @if (_processing) { Processing... } else { Create Booking } @code { [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private CreateBookingValidator _validator = new(); private CreateBookingRequest _model = new() { Status = Indotalent.Data.Enums.BookingStatus.Draft }; private LookupBookingDataResponse _lookupData = new(); private bool _processing = false; private DateTime? _startDate = DateTime.Today; private TimeSpan? _startTime = DateTime.Now.TimeOfDay; private DateTime? _endDate = DateTime.Today; private TimeSpan? _endTime = DateTime.Now.TimeOfDay.Add(TimeSpan.FromHours(1)); protected override async Task OnInitializedAsync() { var response = await BookingManagerService.GetLookupDataAsync(); if (response != null && response.IsSuccess) { _lookupData = response.Value!; } } private async Task Submit() { 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.CreateBookingAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Booking created successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } catch (Exception ex) { Snackbar.Add($"Error: {ex.Message}", Severity.Error); } finally { _processing = false; } } }