139 lines
4.0 KiB
Plaintext
139 lines
4.0 KiB
Plaintext
@page "/booking-entry"
|
|
@using OnProfNext.Client.Services
|
|
@using OnProfNext.Shared.Models.DTOs
|
|
@inject BookingApiService BookingService
|
|
@inject OrderApiService OrderService
|
|
@inject NavigationManager Navigation
|
|
|
|
<h3 class="mb-4 d-flex justify-content-between align-items-center">
|
|
<span class="text-primary">Zeit buchen</span>
|
|
<button class="btn btn-outline-secondary" @onclick="GoBack">
|
|
<i class="bi bi-arrow-left"></i> Zurück
|
|
</button>
|
|
</h3>
|
|
|
|
@if (isLoading)
|
|
{
|
|
<div class="text-center mt-5">
|
|
<div class="spinner-border text-primary" role="status"></div>
|
|
<p class="mt-3 text-secondary">Daten werden geladen...</p>
|
|
</div>
|
|
}
|
|
else if (errorMessage is not null)
|
|
{
|
|
<div class="alert alert-danger">@errorMessage</div>
|
|
}
|
|
else
|
|
{
|
|
<ul class="nav nav-tabs mb-3">
|
|
<li class="nav-item">
|
|
<button class="nav-link @(activeView == ViewType.Classic ? "active" : "")"
|
|
@onclick="() => activeView = ViewType.Classic">
|
|
<i class="bi bi-calendar-month me-1"></i> Klassische Ansicht
|
|
</button>
|
|
</li>
|
|
<li class="nav-item">
|
|
<button class="nav-link @(activeView == ViewType.Fancy ? "active" : "")"
|
|
@onclick="() => activeView = ViewType.Fancy">
|
|
<i class="bi bi-calendar-week me-1"></i> Fancy Ansicht
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content p-3 border rounded bg-white shadow-sm">
|
|
@if (activeView == ViewType.Classic)
|
|
{
|
|
<ClassicView Bookings="MyBookings" Orders="AvailableOrders"
|
|
OnBookingCreated="ReloadBookings" OnError="ShowError" />
|
|
}
|
|
else
|
|
{
|
|
<FancyView Bookings="MyBookings" Orders="AvailableOrders"
|
|
OnBookingCreated="ReloadBookings" OnError="ShowError" />
|
|
}
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private enum ViewType { Classic, Fancy }
|
|
private ViewType activeView = ViewType.Classic;
|
|
private bool isLoading = true;
|
|
private string? errorMessage;
|
|
private List<BookingDto> MyBookings = new();
|
|
private List<OrderDto> AvailableOrders = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadDataAsync();
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task LoadDataAsync()
|
|
{
|
|
try
|
|
{
|
|
// Lade Bookings des Users
|
|
var (bookingSuccess, bookings, bookingError) = await BookingService.GetMyBookingsAsync();
|
|
if (!bookingSuccess)
|
|
{
|
|
errorMessage = bookingError;
|
|
return;
|
|
}
|
|
MyBookings = bookings ?? new();
|
|
|
|
// Lade Orders des Users
|
|
var (orderSuccess, orders, orderError) = await OrderService.GetMyOrdersAsync();
|
|
if (!orderSuccess)
|
|
{
|
|
errorMessage = orderError;
|
|
return;
|
|
}
|
|
AvailableOrders = orders ?? new();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = $"Fehler beim Laden der Daten: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
private async Task ReloadBookings()
|
|
{
|
|
var (success, bookings, error) = await BookingService.GetMyBookingsAsync();
|
|
if (success)
|
|
{
|
|
MyBookings = bookings ?? new();
|
|
StateHasChanged();
|
|
}
|
|
else
|
|
{
|
|
errorMessage = error;
|
|
}
|
|
}
|
|
|
|
private void ShowError(string error)
|
|
{
|
|
errorMessage = error;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void GoBack() => Navigation.NavigateTo("/projects");
|
|
}
|
|
|
|
<style>
|
|
.nav-tabs .nav-link {
|
|
color: #495057;
|
|
border: none;
|
|
border-bottom: 3px solid transparent;
|
|
}
|
|
|
|
.nav-tabs .nav-link.active {
|
|
color: #0d6efd;
|
|
font-weight: 600;
|
|
border-color: #0d6efd;
|
|
background-color: transparent;
|
|
}
|
|
|
|
.tab-content {
|
|
border-radius: 0.5rem;
|
|
}
|
|
</style> |