200 lines
6.5 KiB
Plaintext
200 lines
6.5 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 IStringLocalizer<Apply> Localizer
|
|
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<h3>@Localizer["Ingenieur Antrag"]</h3>
|
|
@if (!string.IsNullOrEmpty(_message))
|
|
{
|
|
<div class="alert alert-info">@_message</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@if (_showForm)
|
|
{
|
|
<div class="card p-3">
|
|
<p>Bitte laden Sie Ihren Ingenieur-Antrag als PDF-Datei hoch.</p>
|
|
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Titel</label>
|
|
<input id="title" type="text" class="form-control" @bind="_existingApp.Title" maxlength="256"/>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Kurzbeschreibung</label>
|
|
<textarea id="description" class="form-control" rows="3" @bind="_existingApp.ShortDescription" placeholder="Kurze Beschreibung Ihres Ingenieur-Antrags..."></textarea>
|
|
</div>
|
|
|
|
@* <div class="mb-3">
|
|
<label for="pdfUpload" class="form-label">Antrags-PDF</label>
|
|
<InputFile OnChange="@LoadFiles" class="form-control" accept=".pdf"/>
|
|
<div class="form-text">Max Größe: 20MB. Format: Nur PDF.</div>
|
|
</div> *@
|
|
|
|
|
|
<FileManager OnSelectFile="@OnSelectFile" ShowProgress="true" ShowSuccess="true"/>
|
|
|
|
<div class="mt-2">
|
|
<button class="btn btn-primary" @onclick="SubmitApplication" disabled="@(_existingApp?.FileId == 0)">
|
|
@(_existingApp.ApplicationId > 0 ? "Antrag aktualisieren" : "Antrag hochladen")
|
|
</button>
|
|
<button class="btn btn-secondary" @onclick="Cancel">Abbrechen</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
@if (_existingApp.FileId > 0)
|
|
{
|
|
<div class="card">
|
|
<div class="card-header">Ihr Antrag</div>
|
|
<div class="card-body">
|
|
<p>
|
|
<strong>Status:</strong> <span class="badge bg-success">Veröffentlicht</span>
|
|
</p>
|
|
@if (!string.IsNullOrEmpty(_existingApp.Title))
|
|
{
|
|
<p>
|
|
<strong>Titel:</strong> @_existingApp.Title
|
|
</p>
|
|
}
|
|
@if (!string.IsNullOrEmpty(_existingApp.ShortDescription))
|
|
{
|
|
<p>
|
|
<strong>Kurzbeschreibung:</strong> @_existingApp.ShortDescription
|
|
</p>
|
|
}
|
|
<p>
|
|
<strong>Datum:</strong> @_existingApp.CreatedOn.ToShortDateString()
|
|
</p>
|
|
<div class="d-flex gap-2">
|
|
<button class="btn btn-primary" @onclick="EditApp">Antrag aktualisieren</button>
|
|
@if (!_confirmDelete)
|
|
{
|
|
<button class="btn btn-outline-danger" @onclick="() => _confirmDelete = true">Antrag löschen</button>
|
|
}
|
|
else
|
|
{
|
|
<button class="btn btn-danger" @onclick="DeleteApp">Wirklich löschen?</button>
|
|
<button class="btn btn-secondary" @onclick="() => _confirmDelete = false">Abbrechen</button>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
|
|
|
|
private EngineerApplication _existingApp = new EngineerApplication();
|
|
private bool _showForm = true;
|
|
private bool _confirmDelete = false;
|
|
private string _message = "";
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var apps = await ApplicationService.GetApplicationsAsync(ModuleState.ModuleId);
|
|
var userId = PageState.User?.UserId ?? -1;
|
|
_existingApp.Status = "New";
|
|
_existingApp = apps.FirstOrDefault(a => a.UserId == userId, _existingApp);
|
|
|
|
if (_existingApp.FileId > 0)
|
|
{
|
|
_showForm = false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void EditApp()
|
|
{
|
|
_showForm = true;
|
|
}
|
|
|
|
private async Task SubmitApplication()
|
|
{
|
|
if (_existingApp == null || _existingApp.FileId == 0)
|
|
{
|
|
_message = "Bitte wählen Sie eine Datei aus.";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var app = new EngineerApplication
|
|
{
|
|
ApplicationId = _existingApp?.ApplicationId ?? 0,
|
|
ModuleId = ModuleState.ModuleId,
|
|
UserId = PageState.User.UserId,
|
|
FileId = _existingApp.FileId,
|
|
Title = _existingApp.Title,
|
|
ShortDescription = _existingApp.ShortDescription,
|
|
Status = "Published", // Auto-publish
|
|
SubmittedOn = DateTime.UtcNow,
|
|
ApprovedOn = DateTime.UtcNow, // Auto-approved
|
|
};
|
|
|
|
if (app.ApplicationId == 0)
|
|
{
|
|
var result = await ApplicationService.AddApplicationAsync(app);
|
|
_existingApp = result;
|
|
}
|
|
else
|
|
{
|
|
await ApplicationService.UpdateApplicationAsync(app);
|
|
_existingApp = await ApplicationService.GetApplicationAsync(app.ApplicationId, ModuleState.ModuleId);
|
|
}
|
|
|
|
_showForm = false;
|
|
_message = "Antrag erfolgreich veröffentlicht.";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_message = "Fehler: " + ex.Message;
|
|
}
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
NavManager.NavigateTo(NavigateUrl());
|
|
}
|
|
|
|
private async Task DeleteApp()
|
|
{
|
|
try
|
|
{
|
|
await ApplicationService.DeleteApplicationAsync(_existingApp.ApplicationId, ModuleState.ModuleId);
|
|
_existingApp = new EngineerApplication { Status = "New" };
|
|
_showForm = true;
|
|
_confirmDelete = false;
|
|
_message = "Antrag erfolgreich gelöscht.";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_message = "Fehler beim Löschen: " + ex.Message;
|
|
_confirmDelete = false;
|
|
}
|
|
}
|
|
|
|
|
|
private Task OnSelectFile(int fileId)
|
|
{
|
|
_existingApp.FileId = fileId;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
}
|