groceries/Groceries/Stores/StoreForm.razor
James Chapman 2c0f6f1cab
All checks were successful
Docker Image CI / build (push) Successful in 3m8s
Fix error loading Add/Edit Transaction Item page
2024-10-12 16:00:32 +01:00

54 lines
1.7 KiB
Plaintext

@using Groceries.Data
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<AppDbContext> DbContextFactory
<form method="post" @attributes="AdditionalAttributes">
<div class="form-field">
<label class="form-field__label" for="storeRetailerId">Retailer</label>
<select class="form-field__control select" id="storeRetailerId" name="retailerId" required autofocus>
@foreach (var retailer in retailers)
{
<option value="@retailer.Id" selected="@(retailer.Id == Store?.RetailerId)">@retailer.Name</option>
}
</select>
</div>
<div class="form-field">
<label class="form-field__label" for="storeName">Name</label>
<div class="form-field__control input">
<input class="input__control" id="storeName" name="name" value="@Store?.Name" required />
</div>
</div>
<div class="form-field">
<label class="form-field__label" for="storeAddress">
Address <span class="form-field__corner-hint">Optional</span>
</label>
<textarea class="form-field__control textarea" id="storeAddress" name="address" rows="4">@Store?.Address</textarea>
</div>
@ChildContent
</form>
@code {
[Parameter]
public Store? Store { get; set; }
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? AdditionalAttributes { get; set; }
private Retailer[] retailers = [];
protected override async Task OnInitializedAsync()
{
using var dbContext = DbContextFactory.CreateDbContext();
retailers = await dbContext.Retailers
.OrderBy(retailer => retailer.Name)
.ToArrayAsync();
}
}