@inject RedistributableService RedistributableService @inject NavigationManager NavigationManager @inject MessageService MessageService @inject ILogger Logger @if (Id != Guid.Empty) { General Archives Options Scripts } else { @* Add button without RouterLink, prevents routing on disabled/inactive menu item *@ General } @if (TitleTemplate != null) { @TitleTemplate(Redistributable) } else { @Title } @TitleExtraTemplate?.Invoke(Redistributable)
@if (Redistributable?.Id == Id) { @ChildContent?.Invoke(Redistributable) }
@code { [Parameter] public Guid Id { get; set; } [Parameter] public string Title { get; set; } [Parameter] public RenderFragment? TitleTemplate { get; set; } [Parameter] public RenderFragment? TitleExtraTemplate { get; set; } [Parameter] public RenderFragment? ChildContent { get; set; } Redistributable Redistributable { get; set; } = new(); Guid _id; protected override async Task OnParametersSetAsync() { if (_id != Id) { _id = Id; if (_id != Guid.Empty) Redistributable = await RedistributableService .Include(r => r.Games) .Include(r => r.CreatedBy) .Include(r => r.UpdatedBy) .GetAsync(_id); else Redistributable = new(); if (Redistributable == null) NavigationManager.NavigateTo("/Redistributables"); } } public async Task Save() { try { if (_id != Guid.Empty) { await RedistributableService.UpdateAsync(Redistributable); MessageService.Success("Redistributable updated!"); } else { Redistributable = await RedistributableService.AddAsync(Redistributable); NavigationManager.LocationChanged += NotifyRedistributableAdded; NavigationManager.NavigateTo($"/Redistributables/{Redistributable.Id}"); } } catch (Exception ex) { Logger?.LogError(ex, "Redistributable could not be saved!"); MessageService.Error("Redistributable could not be saved!"); } } private void NotifyRedistributableAdded(object? sender, LocationChangedEventArgs e) { NavigationManager.LocationChanged -= NotifyRedistributableAdded; MessageService.Success("Redistributable added!"); } }