111 lines
No EOL
3.6 KiB
Text
111 lines
No EOL
3.6 KiB
Text
@inject RedistributableService RedistributableService
|
|
@inject NavigationManager NavigationManager
|
|
@inject MessageService MessageService
|
|
@inject ILogger<RedistributableEditView> Logger
|
|
|
|
<Layout Class="panel-layout" Style="padding: 24px 0;">
|
|
<Sider Width="200">
|
|
<Menu Mode="@MenuMode.Inline" Style="height: 100%;">
|
|
@if (Id != Guid.Empty)
|
|
{
|
|
<MenuItem RouterLink="@($"/Redistributables/{Id}/General")">General</MenuItem>
|
|
|
|
<MenuItem RouterLink="@($"/Redistributables/{Id}/Archives")">Archives</MenuItem>
|
|
<MenuItem RouterLink="@($"/Redistributables/{Id}/Scripts")">Scripts</MenuItem>
|
|
}
|
|
else
|
|
{
|
|
@* Add button without RouterLink, prevents routing on disabled/inactive menu item *@
|
|
<MenuItem>General</MenuItem>
|
|
}
|
|
</Menu>
|
|
</Sider>
|
|
|
|
<Content>
|
|
<CascadingValue Value="Redistributable">
|
|
<PageHeader>
|
|
<PageHeaderTitle>
|
|
@if (TitleTemplate != null)
|
|
{
|
|
@TitleTemplate(Redistributable)
|
|
}
|
|
else {
|
|
<Text>@Title</Text>
|
|
}
|
|
</PageHeaderTitle>
|
|
|
|
<PageHeaderExtra>
|
|
@TitleExtraTemplate?.Invoke(Redistributable)
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
</CascadingValue>
|
|
|
|
<div class="panel-layout-content">
|
|
@ChildContent?.Invoke(Redistributable)
|
|
</div>
|
|
</Content>
|
|
</Layout>
|
|
|
|
@code {
|
|
[Parameter] public Guid Id { get; set; }
|
|
[Parameter] public string Title { get; set; }
|
|
[Parameter] public RenderFragment<Redistributable>? TitleTemplate { get; set; }
|
|
[Parameter] public RenderFragment<Redistributable>? TitleExtraTemplate { get; set; }
|
|
[Parameter] public RenderFragment<Redistributable>? 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!");
|
|
}
|
|
} |