feat(halloffame): implement image upload and enhance module functionality

- Added image upload system (JPG/PNG, max 5MB) with live preview and removal option
- Fixed Concurrency Exception during deletion (split transactions for reports and entries)
- Optimized card layout: consistent height and height-based truncation for descriptions
- Added sort direction toggle (Ascending/Descending) with arrow icons for Date, Name, and Year
- Refactored HallOfFameService to use streams for Server/Wasm compatibility
- Improved error handling and UI feedback for upload and delete operations
This commit is contained in:
Adam Gaiswinkler
2026-02-10 17:45:48 +01:00
parent 2d8c6736a7
commit 1bff5ebbbd
18 changed files with 956 additions and 127 deletions

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net;
using System.Threading.Tasks;
using Oqtane.Services;
using Oqtane.Shared;
using System.Text.Json;
namespace SZUAbsolventenverein.Module.HallOfFame.Services
{
@@ -18,8 +20,11 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
Task<Models.HallOfFame> AddHallOfFameAsync(Models.HallOfFame HallOfFame);
Task<Models.HallOfFame> UpdateHallOfFameAsync(Models.HallOfFame HallOfFame);
Task DeleteHallOfFameAsync(int HallOfFameId, int ModuleId);
Task ReportAsync(int HallOfFameId, int ModuleId, string reason);
Task<List<Models.HallOfFameReport>> GetHallOfFameReportsAsync(int HallOfFameId, int ModuleId);
Task DeleteHallOfFameReportAsync(int HallOfFameReportId, int ModuleId);
Task<string> UploadFileAsync(System.IO.Stream stream, string fileName, int ModuleId);
}
public class HallOfFameService : ServiceBase, IHallOfFameService
@@ -30,8 +35,7 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
public async Task<List<Models.HallOfFame>> GetHallOfFamesAsync(int ModuleId)
{
List<Models.HallOfFame> HallOfFames = await GetJsonAsync<List<Models.HallOfFame>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Models.HallOfFame>().ToList());
return HallOfFames.OrderBy(item => item.Name).ToList();
return await GetJsonAsync<List<Models.HallOfFame>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Models.HallOfFame>().ToList());
}
public async Task<Models.HallOfFame> GetHallOfFameAsync(int HallOfFameId, int ModuleId)
@@ -58,5 +62,38 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
{
await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{HallOfFameId}/{ModuleId}", EntityNames.Module, ModuleId));
}
public async Task ReportAsync(int HallOfFameId, int ModuleId, string reason)
{
await PutAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/report/{HallOfFameId}?reason={WebUtility.UrlEncode(reason)}", EntityNames.Module, ModuleId));
}
public async Task<List<Models.HallOfFameReport>> GetHallOfFameReportsAsync(int HallOfFameId, int ModuleId)
{
return await GetJsonAsync<List<Models.HallOfFameReport>>(CreateAuthorizationPolicyUrl($"{Apiurl}/reports/{HallOfFameId}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Models.HallOfFameReport>().ToList());
}
public async Task DeleteHallOfFameReportAsync(int HallOfFameReportId, int ModuleId)
{
await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/report/{HallOfFameReportId}/{ModuleId}", EntityNames.Module, ModuleId));
}
public async Task<string> UploadFileAsync(System.IO.Stream stream, string fileName, int ModuleId)
{
var uri = CreateAuthorizationPolicyUrl($"{Apiurl}/upload", EntityNames.Module, ModuleId);
using var content = new MultipartFormDataContent();
var fileContent = new StreamContent(stream);
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
content.Add(fileContent, "file", fileName);
var response = await GetHttpClient().PostAsync(uri, content);
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<Dictionary<string, string>>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
return result["url"];
}
return null;
}
}
}