183 lines
7.0 KiB
Plaintext
183 lines
7.0 KiB
Plaintext
@using SZUAbsolventenverein.Module.PremiumArea.Services
|
|
@using SZUAbsolventenverein.Module.PremiumArea.Models
|
|
@namespace SZUAbsolventenverein.Module.PremiumArea
|
|
@inherits ModuleBase
|
|
@inject IEngineerApplicationService ApplicationService
|
|
@inject NavigationManager NavManager
|
|
@inject Oqtane.Services.IUserService UserService
|
|
|
|
@if (Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin) || Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, "Premium Member"))
|
|
{
|
|
<h3>Ingenieur-Anträge</h3>
|
|
|
|
@if (_applications == null)
|
|
{
|
|
<p>Prüfe Premium-Zugang...</p>
|
|
}
|
|
else if (_applications.Count == 0)
|
|
{
|
|
<div class="alert alert-warning">
|
|
Keine Anträge gefunden.
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="row">
|
|
@foreach (var app in _applications)
|
|
{
|
|
<div class="col-md-4 mb-3">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<h5 class="card-title">@(string.IsNullOrEmpty(app.Title) ? "Ingenieur-Antrag" : app.Title)</h5>
|
|
<h6 class="card-subtitle mb-2 text-muted">von @GetUserName(app.UserId)</h6>
|
|
@if (!string.IsNullOrEmpty(app.ShortDescription))
|
|
{
|
|
<p class="card-text">@app.ShortDescription</p>
|
|
}
|
|
<p class="card-text text-muted">
|
|
<small>
|
|
<strong>Datum:</strong> @(app.ApprovedOn?.ToShortDateString() ?? app.CreatedOn.ToShortDateString())
|
|
</small>
|
|
</p>
|
|
<div class="d-flex gap-2">
|
|
<button class="btn btn-primary btn-sm" @onclick="@(async () => ShowDetail(app))">PDF ansehen</button>
|
|
<a href="@(PageState.Alias.Path == "" ? "" : "/" + PageState.Alias.Path)/api/file/download/@(app.FileId)/attach" target="_blank" class="btn btn-outline-secondary btn-sm">Herunterladen</a>
|
|
<button class="btn btn-outline-danger btn-sm" @onclick="@(() => InitReport(app))">Melden</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="alert alert-warning">
|
|
Sie müssen Premium Kunde sein um diese Funktion zu nutzen.
|
|
</div>
|
|
}
|
|
|
|
@if (_selectedApp != null)
|
|
{
|
|
<div class="modal d-block" tabindex="-1">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Antrags-PDF</h5>
|
|
<button type="button" class="btn-close" @onclick="@(() => _selectedApp = null)"></button>
|
|
</div>
|
|
<div class="modal-body p-0">
|
|
<div style="min-height: 600px; height: 75vh;">
|
|
<iframe src="@(PageState.Alias.Path == "" ? "" : "/" + PageState.Alias.Path)/api/file/download/@(_selectedApp.FileId)" style="width: 100%; height: 100%; border: none;" allowfullscreen></iframe>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" @onclick="@(() => _selectedApp = null)">Schließen</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-backdrop fade show"></div>
|
|
}
|
|
|
|
@if (_reportApp != null)
|
|
{
|
|
<div class="modal d-block" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Antrag melden</h5>
|
|
<button type="button" class="btn-close" @onclick="@(() => _reportApp = null)"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Bitte geben Sie einen Grund an, warum Sie diesen Antrag melden (von @GetUserName(_reportApp.UserId)).</p>
|
|
<textarea class="form-control" rows="3" @bind="_reportReason" placeholder="Grund..."></textarea>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" @onclick="@(() => _reportApp = null)">Abbrechen</button>
|
|
<button type="button" class="btn btn-danger" @onclick="SubmitReport">Meldung absenden</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-backdrop fade show"></div>
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
|
|
|
|
private List<EngineerApplication> _applications;
|
|
private EngineerApplication _selectedApp;
|
|
private EngineerApplication _reportApp;
|
|
private string _reportReason;
|
|
private Dictionary<int, string> _userNames = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var published = await ApplicationService.GetApplicationsAsync(ModuleState.ModuleId, "Published");
|
|
var approved = await ApplicationService.GetApplicationsAsync(ModuleState.ModuleId, "Approved");
|
|
|
|
_applications = new List<EngineerApplication>();
|
|
if (published != null) _applications.AddRange(published);
|
|
if (approved != null) _applications.AddRange(approved);
|
|
|
|
_applications = _applications.GroupBy(a => a.ApplicationId).Select(g => g.First()).ToList();
|
|
|
|
// Benutzernamen laden
|
|
foreach (var userId in _applications.Select(a => a.UserId).Distinct())
|
|
{
|
|
try
|
|
{
|
|
var user = await UserService.GetUserAsync(userId, ModuleState.SiteId);
|
|
_userNames[userId] = user?.DisplayName ?? $"Benutzer {userId}";
|
|
}
|
|
catch
|
|
{
|
|
_userNames[userId] = $"Benutzer {userId}";
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
_applications = null;
|
|
}
|
|
}
|
|
|
|
private void ShowDetail(EngineerApplication app)
|
|
{
|
|
_selectedApp = app;
|
|
}
|
|
|
|
private void InitReport(EngineerApplication app)
|
|
{
|
|
_reportApp = app;
|
|
_reportReason = "";
|
|
}
|
|
|
|
private async Task SubmitReport()
|
|
{
|
|
if (_reportApp == null || string.IsNullOrWhiteSpace(_reportReason)) return;
|
|
|
|
try
|
|
{
|
|
await ApplicationService.ReportApplicationAsync(_reportApp.ApplicationId, ModuleState.ModuleId, _reportReason);
|
|
_reportApp = null;
|
|
AddModuleMessage("Antrag erfolgreich gemeldet.", MessageType.Success);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AddModuleMessage("Fehler beim Melden: " + ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private string GetUserName(int userId)
|
|
{
|
|
return _userNames.TryGetValue(userId, out var name) ? name : $"Benutzer {userId}";
|
|
}
|
|
|
|
}
|