2024-03-30 13:07:27 -05:00
|
|
|
@page "/Metadata/Companies"
|
2024-10-16 02:06:02 -05:00
|
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
2025-02-01 02:21:34 -06:00
|
|
|
@inject CompanyService CompanyService
|
2024-03-30 13:07:27 -05:00
|
|
|
@inject IMessageService MessageService
|
2024-07-07 16:33:46 -05:00
|
|
|
@inject ILogger<Index> Logger
|
2024-03-30 13:07:27 -05:00
|
|
|
|
2024-12-12 17:35:52 -06:00
|
|
|
<PageHeader Title="Companies" />
|
|
|
|
|
|
|
|
|
|
<DataTable
|
2024-11-27 21:01:25 -06:00
|
|
|
TItem="Company"
|
2025-03-17 00:50:36 -05:00
|
|
|
@ref="Table"
|
2024-12-31 18:21:41 -06:00
|
|
|
Size="TableSize.Small"
|
2025-01-21 18:48:01 -06:00
|
|
|
Responsive
|
|
|
|
|
Searchable
|
|
|
|
|
SearchProperty="c => c.Name">
|
2024-12-12 17:35:52 -06:00
|
|
|
<RightToolbar>
|
|
|
|
|
<Button OnClick="() => OpenEdit(null)" Type="@ButtonType.Primary">Add Company</Button>
|
|
|
|
|
</RightToolbar>
|
|
|
|
|
<Columns>
|
2025-01-19 14:50:12 -06:00
|
|
|
<BoundDataColumn Property="c => c.Name" Sortable DefaultSortOrder="SortDirection.Ascending" />
|
2025-03-17 02:02:17 -05:00
|
|
|
<BoundDataColumn Property="c => c.CreatedOn" Title="Created On" Sortable>
|
|
|
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
|
|
|
</BoundDataColumn>
|
2025-01-19 14:50:12 -06:00
|
|
|
<BoundDataColumn Property="c => c.CreatedBy != null ? c.CreatedBy.UserName : String.Empty" Title="Created By" Sortable Include="CreatedBy" />
|
2025-03-17 02:02:17 -05:00
|
|
|
<BoundDataColumn Property="c => c.UpdatedOn" Title="Updated On" Sortable>
|
|
|
|
|
<LocalTime Value="context.UpdatedOn" />
|
|
|
|
|
</BoundDataColumn>
|
2025-01-19 14:50:12 -06:00
|
|
|
<BoundDataColumn Property="c => c.UpdatedBy != null ? c.UpdatedBy.UserName : String.Empty" Title="Updated By" Sortable Include="UpdatedBy" />
|
2025-01-20 01:22:56 -06:00
|
|
|
<BoundDataColumn Property="c => c.DevelopedGames.Count" Sortable Title="Developed Games" Include="DevelopedGames" />
|
|
|
|
|
<BoundDataColumn Property="c => c.PublishedGames.Count" Sortable Title="Published Games" Include="PublishedGames" />
|
2025-05-23 02:17:06 -05:00
|
|
|
<DataActions TData="string">
|
2026-02-08 16:09:51 -06:00
|
|
|
<Flex Gap="FlexGap.Small" Align="FlexAlign.Center" Justify="FlexJustify.End">
|
|
|
|
|
<Button OnClick="() => OpenEdit(context)" Type="@ButtonType.Primary">Edit</Button>
|
|
|
|
|
@* TODO: Add seperate Edit page and navigate to it *@
|
|
|
|
|
@* <a href="@($"/Metadata/Engines/{context.Id}")" class="ant-btn ant-btn-primary">Edit</a> *@
|
2025-06-23 22:14:34 +02:00
|
|
|
|
2026-02-08 16:09:51 -06:00
|
|
|
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this company?">
|
|
|
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Close" Danger/>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</Flex>
|
2024-12-12 17:35:52 -06:00
|
|
|
</DataActions>
|
|
|
|
|
</Columns>
|
|
|
|
|
</DataTable>
|
2024-03-30 13:07:27 -05:00
|
|
|
|
|
|
|
|
<Modal Title="@(CompanyContext.Id == Guid.Empty ? "New Company" : "Edit Company")"
|
|
|
|
|
@bind-Visible="@EditCompanyVisible"
|
|
|
|
|
OnOk="UpdateOrAdd"
|
|
|
|
|
OnCancel="CloseEdit">
|
|
|
|
|
<Form Model="@CompanyContext">
|
|
|
|
|
<FormItem Label="Name">
|
2025-02-23 09:27:34 -06:00
|
|
|
<Input @bind-Value="@context.Name" AutoFocus />
|
2024-03-30 13:07:27 -05:00
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
2025-03-17 00:50:36 -05:00
|
|
|
@code {
|
|
|
|
|
DataTable<Company> Table;
|
2024-03-30 13:07:27 -05:00
|
|
|
bool EditCompanyVisible = false;
|
2025-01-19 14:50:12 -06:00
|
|
|
Company CompanyContext = new();
|
2024-03-30 13:07:27 -05:00
|
|
|
|
2024-11-22 02:05:44 -06:00
|
|
|
async Task UpdateOrAdd()
|
2024-03-30 13:07:27 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
if (CompanyContext.Id == Guid.Empty)
|
2024-03-30 13:07:27 -05:00
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
await CompanyService.AddMissingAsync(x => x.Name == CompanyContext.Name, CompanyContext);
|
2024-11-25 22:29:56 -06:00
|
|
|
|
2025-02-01 02:21:34 -06:00
|
|
|
MessageService.Success($"{CompanyContext.Name} was added!");
|
2024-03-30 13:07:27 -05:00
|
|
|
}
|
2025-02-01 02:21:34 -06:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await CompanyService.UpdateAsync(CompanyContext);
|
2024-03-30 13:07:27 -05:00
|
|
|
|
2025-02-01 02:21:34 -06:00
|
|
|
MessageService.Success($"{CompanyContext.Name} was updated!");
|
|
|
|
|
}
|
2024-03-30 13:07:27 -05:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (CompanyContext.Id == Guid.Empty)
|
|
|
|
|
MessageService.Error($"Could not add {CompanyContext.Name}!");
|
|
|
|
|
else
|
2024-07-07 16:33:46 -05:00
|
|
|
MessageService.Error($"Could not update {CompanyContext.Name}!");
|
|
|
|
|
|
|
|
|
|
Logger.LogError(ex, $"Could not update/add {CompanyContext.Name}!");
|
2024-03-30 13:07:27 -05:00
|
|
|
}
|
|
|
|
|
|
2025-12-05 16:28:39 -06:00
|
|
|
await Table.ReloadAsync();
|
2025-03-17 00:50:36 -05:00
|
|
|
|
2024-03-30 13:07:27 -05:00
|
|
|
await CloseEdit();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 22:14:34 +02:00
|
|
|
async Task OpenEdit(Company? company)
|
2024-03-30 13:07:27 -05:00
|
|
|
{
|
2025-06-23 22:14:34 +02:00
|
|
|
// query new instance, or create a new Edit context instance
|
|
|
|
|
CompanyContext = company != null ? await CompanyService.GetAsync(company.Id) : default!;
|
|
|
|
|
CompanyContext ??= new();
|
2024-03-30 13:07:27 -05:00
|
|
|
|
|
|
|
|
EditCompanyVisible = true;
|
|
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-22 02:05:44 -06:00
|
|
|
async Task CloseEdit()
|
2024-03-30 13:07:27 -05:00
|
|
|
{
|
|
|
|
|
EditCompanyVisible = false;
|
|
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
2025-03-17 00:50:36 -05:00
|
|
|
|
|
|
|
|
async Task Delete(Company company)
|
2024-03-30 13:07:27 -05:00
|
|
|
{
|
2025-03-17 00:50:36 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await CompanyService.DeleteAsync(company);
|
|
|
|
|
|
|
|
|
|
MessageService.Success("Company deleted!");
|
|
|
|
|
|
2025-12-05 16:28:39 -06:00
|
|
|
await Table.ReloadAsync();
|
2025-03-17 00:50:36 -05:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageService.Error("Could not delete company!");
|
|
|
|
|
Logger?.LogError(ex, "Could not delete company");
|
|
|
|
|
}
|
2024-11-27 21:01:25 -06:00
|
|
|
}
|
2024-03-30 13:07:27 -05:00
|
|
|
}
|