@using Groceries.Data @using Microsoft.EntityFrameworkCore @layout Layout @implements IDisposable @inject IDbContextFactory DbContextFactory Groceries – Stores

Stores

New store
Edit
@code { private record StoreModel { public Guid Id { get; init; } public required string Retailer { get; init; } public required string Name { get; init; } public int TransactionsCount { get; init; } } private AppDbContext? dbContext; private IQueryable stores = null!; private PaginationState pagination = new(); [SupplyParameterFromQuery] public string? Search { get; set; } protected override void OnParametersSet() { dbContext ??= DbContextFactory.CreateDbContext(); var storesQuery = dbContext.Stores.AsQueryable(); if (!string.IsNullOrEmpty(Search)) { var searchPattern = $"%{Search}%"; storesQuery = storesQuery .Where(store => EF.Functions.ILike(store.Retailer!.Name + ' ' + store.Name, searchPattern)); } stores = storesQuery .Select(store => new StoreModel { Id = store.Id, Retailer = store.Retailer!.Name, Name = store.Name, TransactionsCount = store.Transactions!.Count(), }) .OrderBy(store => store.Retailer) .ThenBy(store => store.Name); } public void Dispose() { dbContext?.Dispose(); } }