Files
Module.AdminModules/Client/Modules/SZUAbsolventenverein.Module.ReportSystem/Index.razor
2026-02-19 16:37:45 +01:00

99 lines
3.5 KiB
Plaintext

@namespace SZUAbsolventenverein.Module.ReportSystem
@using Microsoft.VisualBasic.FileIO
@using SZUAbsolventenverein.Module.ReportSystem.Models
@using SZUAbsolventenverein.Module.ReportSystem.Services
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IReportSystemReportingService ReportingService
@inject IStringLocalizer<Index> Localizer
@inject IModuleService ModuleService
@if (_reportings == null)
{
<p><em>Loading...</em></p>
}
else
{
<br />
<br />
@if (_reportings.Count != 0)
{
<Pager Items="@_reportings">
<Header>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th>@Localizer["Submitter"]</th>
<th>@Localizer["Note"]</th>
<th>@Localizer["Name"]</th>
</Header>
<Row>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.ReportingID)" ResourceKey="Edit" /></td>
<td><ActionDialog Header="Delete AdminModules" Message="Are You Sure You Wish To Delete This AdminModules?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" ResourceKey="Delete" Id="@context.ReportingID.ToString()" /></td>
<td>@context.CreatedBy</td>
<td>@context.CreatedOn</td>
<td>@context.ModuleId</td>
<td>@context.ReportingID</td>
<td>@context.Note</td>
<td>@context.Reason</td>
</Row>
</Pager>
}
else
{
<p>@Localizer["Message.DisplayNone"]</p>
}
}
@code {
public override string RenderMode => RenderModes.Interactive;
public override List<Resource> Resources => new List<Resource>()
{
new Stylesheet("_content/SZUAbsolventenverein.Module.ReportSystem/Module.css"),
new Script("_content/SZUAbsolventenverein.Module.ReportSystem/Module.js")
};
private List<Reporting> _reportings = new List<Reporting>();
private Dictionary<int, Module> _modules = new Dictionary<int, Module>();
protected override async Task OnInitializedAsync()
{
try
{
_reportings = await ReportingService.GetReportsAsync(ModuleState.ModuleId);
foreach (var moduleId in _reportings.Select(r => r.ModuleId).Distinct())
{
Console.WriteLine(moduleId);
try
{
_modules.Add(moduleId, await ModuleService.GetModuleAsync(moduleId));
await logger.LogDebug(LogFunction.Create, "Module found {ModuleId} while loading Modules for Reportings.", moduleId);
}
catch (Exception ex)
{
_modules.Add(moduleId, new Module {Title = $"Module not found {ex.Message}"});
await logger.LogDebug("Module not found {ModuleId} while loading Modules for Reportings. {error}", moduleId, ex);
}
}
}
catch (Exception ex)
{
logger.LogError("Error fetching reportings: {Message}", ex.Message);
};
}
private async Task Delete(Reporting reporting)
{
try
{
await ReportingService.DeleteReportingAsync(reporting.ReportingID, ModuleState.ModuleId);
_reportings.Remove(reporting);
StateHasChanged();
}
catch (Exception ex)
{
logger.LogError("Error deleting reporting: {Message}", ex.Message);
}
}
}