59 lines
2.3 KiB
Plaintext
59 lines
2.3 KiB
Plaintext
@using Groceries.Data
|
|
|
|
@layout Layout
|
|
@inject AppDbContext DbContext
|
|
|
|
<PageTitle>Groceries – Transactions</PageTitle>
|
|
|
|
<header class="row">
|
|
<h1 class="row__fill">Transactions</h1>
|
|
<a class="button button--primary form-field" href="/transactions/new">New transaction</a>
|
|
</header>
|
|
|
|
<section class="table">
|
|
<Table Items="transactions" Pagination="pagination" HeaderClass="table__header--shaded">
|
|
<PropertyTableColumn Property="t => t.CreatedAt" Title="Date" Sortable="true" Context="createdAt">
|
|
<time datetime="@createdAt.ToString("o")">@createdAt.ToLongDateString()</time>
|
|
</PropertyTableColumn>
|
|
<PropertyTableColumn Property="t => t.Store" Fill="true" Sortable="true" />
|
|
<PropertyTableColumn Property="t => t.TotalItems" Title="Items" Sortable="true" />
|
|
<PropertyTableColumn Property="t => t.TotalAmount" Title="Amount" Format="c" Sortable="true" />
|
|
@* <TemplateTableColumn>
|
|
<a class="link" href="/transactions/@context.Id">View</a>
|
|
</TemplateTableColumn> *@
|
|
</Table>
|
|
<TablePaginator State="pagination" />
|
|
</section>
|
|
|
|
@code {
|
|
private record TransactionModel
|
|
{
|
|
public Guid Id { get; init; }
|
|
public DateTime CreatedAt { get; init; }
|
|
public required string Store { get; init; }
|
|
public decimal TotalAmount { get; init; }
|
|
public int TotalItems { get; init; }
|
|
}
|
|
|
|
private IQueryable<TransactionModel> transactions = null!;
|
|
private PaginationState pagination = new();
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
transactions = DbContext.Transactions
|
|
.Join(
|
|
DbContext.TransactionTotals,
|
|
transaction => transaction.Id,
|
|
transactionTotal => transactionTotal.TransactionId,
|
|
(transaction, transactionTotal) => new TransactionModel
|
|
{
|
|
Id = transaction.Id,
|
|
CreatedAt = transaction.CreatedAt,
|
|
Store = string.Concat(transaction.Store!.Retailer!.Name, " ", transaction.Store.Name),
|
|
TotalAmount = transactionTotal.Total,
|
|
TotalItems = transaction.Items.Sum(item => item.Quantity),
|
|
})
|
|
.OrderByDescending(transaction => transaction.CreatedAt);
|
|
}
|
|
}
|