|
| 1 | +@page "/" |
| 2 | +@using CqrsSqlServer.DataModel.Entities |
| 3 | +@using CqrsSqlServer.DataModel |
| 4 | +@using Microsoft.EntityFrameworkCore |
| 5 | +@inject CqrsSqlServerContext DbContext |
| 6 | + |
| 7 | +<PageTitle>Product Data</PageTitle> |
| 8 | +<div class="d-flex flex-grow-1 gap-4"> |
| 9 | + <MudText Typo="Typo.h3" GutterBottom="true">Product Data</MudText> |
| 10 | + <MudFab Color="Color.Primary" StartIcon="@Icons.Material.Filled.Refresh" OnClick="RefreshCallback"></MudFab> |
| 11 | +</div> |
| 12 | + |
| 13 | +<MudTable Items="_products" Hover="true" SortLabel="Sort By" Elevation="0" Loading="@_loading"> |
| 14 | + <HeaderContent> |
| 15 | + <MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<ProductListing, object>(x=>x.ProductId)">Id</MudTableSortLabel></MudTh> |
| 16 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.ProductName)">Name</MudTableSortLabel></MudTh> |
| 17 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.Price)">Price</MudTableSortLabel></MudTh> |
| 18 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.AllInventory)">Inventory</MudTableSortLabel></MudTh> |
| 19 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.SoldUnits)">Sold</MudTableSortLabel></MudTh> |
| 20 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.TotalRevenue)">Revenue</MudTableSortLabel></MudTh> |
| 21 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.Created)">Created</MudTableSortLabel></MudTh> |
| 22 | + <MudTh><MudTableSortLabel SortBy="new Func<ProductListing, object>(x=>x.LastModified)">Updated</MudTableSortLabel></MudTh> |
| 23 | + </HeaderContent> |
| 24 | + <RowTemplate> |
| 25 | + <MudTd DataLabel="Id">@context.ProductId</MudTd> |
| 26 | + <MudTd DataLabel="Name">@context.ProductName</MudTd> |
| 27 | + <MudTd DataLabel="Price">@context.Price</MudTd> |
| 28 | + <MudTd DataLabel="Inventory">@context.AllInventory</MudTd> |
| 29 | + <MudTd DataLabel="Sold">@context.SoldUnits</MudTd> |
| 30 | + <MudTd DataLabel="Revenue">@context.TotalRevenue</MudTd> |
| 31 | + <MudTd DataLabel="Created">@context.Created</MudTd> |
| 32 | + <MudTd DataLabel="Updated">@context.LastModified</MudTd> |
| 33 | + </RowTemplate> |
| 34 | + <PagerContent> |
| 35 | + <MudTablePager PageSizeOptions="new int[]{10, 50, 100}" /> |
| 36 | + </PagerContent> |
| 37 | +</MudTable> |
| 38 | + |
| 39 | +@code { |
| 40 | + private ProductListing[] _products = Array.Empty<ProductListing>(); |
| 41 | + private bool _loading = true; |
| 42 | + |
| 43 | + protected override async Task OnInitializedAsync() |
| 44 | + { |
| 45 | + _products = await DbContext.Products.ToArrayAsync(); |
| 46 | + _loading = false; |
| 47 | + } |
| 48 | + |
| 49 | + private async Task RefreshCallback() |
| 50 | + { |
| 51 | + _loading = true; |
| 52 | + StateHasChanged(); |
| 53 | + _products = await DbContext.Products.ToArrayAsync(); |
| 54 | + _loading = false; |
| 55 | + StateHasChanged(); |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments