@page "/profile"

My Account

Order History
@if (orderHistory != null) { @foreach (var order in orderHistory) {
@order.OrderId
@order.OrderDate.ToString("MMM dd, yyyy")
@order.Status
@order.ProductTitle
Shipped to: @order.ShippingAddressName
Total Paid R @order.Total.ToString("N2")
} } else {
Loading order history...
}
@*
Order History
@if (orderHistory != null) { @foreach (var order in orderHistory) { } } else { }
Order ID Title Date Address Status Total Invoice
@order.OrderId @order.DisplayTitle @order.OrderDate.ToString("MMM dd, yyyy") @order.ShippingAddressName @order.Status R @order.Total.ToString("N2")
Loading order history...
*@
Saved Addresses
@if (!showAddForm && editingAddress == null) { }
@if (showAddForm) {
New Address
} @if (editingAddress != null) {
Edit Address
} @foreach (var addr in savedAddresses) {
@addr.Name

@addr.Street, @addr.City, @addr.PostalCode

@if (addr.IsBilling) { [Billing] } @if (addr.IsShipping) { [Shipping] }
}
Profile Settings

Manage your password and profile data here.

@code { private bool showAddForm = false; private AddressItem? editingAddress = null; private string newAddressName = ""; private string newStreetAddress = ""; private string newCity = ""; private string newPostalCode = ""; private bool isBilling, isShipping; private List orderHistory = new() { new OrderItem { OrderId = "#MB-2026-9481", ProductId = "introduction-to-blazor", ProductTitle = "Introduction to Blazor WebAssembly Framework Development", OrderDate = new DateTime(2026, 5, 20), ShippingAddressName = "Home Address", Status = "Shipped", Total = 720.00 }, new OrderItem { OrderId = "#MB-2026-8712", ProductId = "mastering-css-isolation", ProductTitle = "Mastering CSS Isolation in Modern .NET Web Applications Architecture", OrderDate = new DateTime(2026, 4, 14), ShippingAddressName = "Midrand Books Warehouse", Status = "Delivered", Total = 890.00 } }; private List savedAddresses = new() { new AddressItem { Id = 1, Name = "Home Address", Street = "12 Main Road", City = "Midrand", PostalCode = "1685", IsBilling = true, IsShipping = true, IsPrimary = true }, new AddressItem { Id = 2, Name = "Corporate Office", Street = "45 Challink Street", City = "Halfway House", PostalCode = "1682", IsBilling = true, IsShipping = false, IsPrimary = false }, new AddressItem { Id = 3, Name = "Midrand Books Warehouse", Street = "Unit 8, Corporate Park North", City = "Randjespark", PostalCode = "1683", IsBilling = false, IsShipping = true, IsPrimary = false } }; private void DownloadInvoice(string orderId) { // Handle invoice downloading logic here } private void OpenAddForm() { editingAddress = null; showAddForm = true; } private void SaveAddress() { if (!string.IsNullOrWhiteSpace(newAddressName) && !string.IsNullOrWhiteSpace(newStreetAddress)) { var nextId = savedAddresses.Any() ? savedAddresses.Max(a => a.Id) + 1 : 1; var newItem = new AddressItem { Id = nextId, Name = newAddressName, Street = newStreetAddress, City = newCity, PostalCode = newPostalCode, IsBilling = isBilling, IsShipping = isShipping, IsPrimary = !savedAddresses.Any() }; savedAddresses.Add(newItem); ResetAddForm(); } } private void ResetAddForm() { newAddressName = ""; newStreetAddress = ""; newCity = ""; newPostalCode = ""; isBilling = false; isShipping = false; showAddForm = false; } private void StartEditing(AddressItem addr) { showAddForm = false; editingAddress = new AddressItem { Id = addr.Id, Name = addr.Name, Street = addr.Street, City = addr.City, PostalCode = addr.PostalCode, IsBilling = addr.IsBilling, IsShipping = addr.IsShipping, IsPrimary = addr.IsPrimary }; } private void UpdateAddress() { if (editingAddress != null) { var target = savedAddresses.FirstOrDefault(a => a.Id == editingAddress.Id); if (target != null) { target.Name = editingAddress.Name; target.Street = editingAddress.Street; target.City = editingAddress.City; target.PostalCode = editingAddress.PostalCode; target.IsBilling = editingAddress.IsBilling; target.IsShipping = editingAddress.IsShipping; } editingAddress = null; } } private void CancelEditing() { editingAddress = null; } private void DeleteAddress(AddressItem addr) { if (editingAddress?.Id == addr.Id) { editingAddress = null; } savedAddresses.Remove(addr); if (addr.IsPrimary && savedAddresses.Any()) { savedAddresses.First().IsPrimary = true; } } private void SetPrimary(AddressItem target, ChangeEventArgs e) { var isChecked = (bool)(e.Value ?? false); if (isChecked) { foreach (var addr in savedAddresses) { addr.IsPrimary = (addr.Id == target.Id); } } else { target.IsPrimary = false; } } public class AddressItem { public int Id { get; set; } public string Name { get; set; } = ""; public string Street { get; set; } = ""; public string City { get; set; } = ""; public string PostalCode { get; set; } = ""; public bool IsBilling { get; set; } public bool IsShipping { get; set; } public bool IsPrimary { get; set; } } public class OrderItem { public string OrderId { get; set; } = ""; public string ProductId { get; set; } = ""; public string ProductTitle { get; set; } = ""; public DateTime OrderDate { get; set; } public string ShippingAddressName { get; set; } = ""; public string Status { get; set; } = ""; public double Total { get; set; } public string DisplayTitle { get { if (string.IsNullOrWhiteSpace(ProductTitle)) return ""; const int maxLength = 21; // Shifted slightly down from 25 to protect bounds against lower resolutions return ProductTitle.Length <= maxLength ? ProductTitle : $"{ProductTitle.Substring(0, maxLength)}..."; } } } }