@page "/" @using BlazorFrontend.Services @using LibraryManagement.Shared.Models @using Microsoft.AspNetCore.Components.Authorization @inject LibraryApiClient ApiClient @inject AuthenticationStateProvider AuthStateProvider @inject NavigationManager Navigation Dashboard

Welcome Back

Here's what's happening with the library today.

@if (_isLoading) {
} else { @if (_loyaltyAccount != null) {

Your Loyalty Status

@_loyaltyAccount.CurrentBalance.ToString("N0")

Points Earned

Member Account: Verified

Current Tier
@_loyaltyAccount.Tier
}
Books
@_totalBooks
Total in catalog
Active Loans
@_activeLoans
Checking out right now
Overdue
@_overdueLoans
Require attention
Active Members
@_totalMembers
In the community
@if (_recentBooks.Any()) {

Recent Arrivals

Browse All
@foreach (var book in _recentBooks) { }
}

Explore the Library

Access thousands of books across all categories with a premium member account.

My Current Loans

Don't forget to return your books on time to avoid late fees.

} @code { private int _totalBooks = 0; private int _activeLoans = 0; private int _overdueLoans = 0; private int _totalMembers = 0; private IEnumerable _recentBooks = Enumerable.Empty(); private LoyaltyAccountDto? _loyaltyAccount; private bool _isLoading = true; protected override async Task OnInitializedAsync() { try { // 1. Basic Stats (Public) var books = await ApiClient.GetBooksAsync(); _totalBooks = books.Count(); _recentBooks = books.Take(6); // 2. Personal/Authenticated Stats var authState = await AuthStateProvider.GetAuthenticationStateAsync(); var user = authState.User; if (user.Identity?.IsAuthenticated == true) { // Fetch borrowings try { var borrowings = await ApiClient.GetMyBorrowingsAsync(); _activeLoans = borrowings.Count(b => b.Status == "Borrowed"); _overdueLoans = borrowings.Count(b => b.Status == "Overdue" || (b.Status == "Borrowed" && b.DueDate < DateTime.UtcNow)); } catch { } // Fetch loyalty try { _loyaltyAccount = await ApiClient.GetMyLoyaltyAccountAsync(); } catch { } // 3. Librarian Only Stats if (user.IsInRole("Librarian")) { try { var members = await ApiClient.GetUsersAsync(); _totalMembers = members.Count(); } catch { } } } } catch (Exception ex) { Console.WriteLine("Error loading dashboard data: " + ex.Message); } finally { _isLoading = false; } } }