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:
@@ -2,12 +2,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Net.Http;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Shared;
|
||||
using SZUAbsolventenverein.Module.HallOfFame.Repository;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.HallOfFame.Services
|
||||
{
|
||||
@@ -18,14 +22,16 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
|
||||
private readonly ILogManager _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public ServerHallOfFameService(IHallOfFameRepository HallOfFameRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
||||
public ServerHallOfFameService(IHallOfFameRepository HallOfFameRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor, IWebHostEnvironment environment)
|
||||
{
|
||||
_HallOfFameRepository = HallOfFameRepository;
|
||||
_userPermissions = userPermissions;
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
_alias = tenantManager.GetAlias();
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
public Task<List<Models.HallOfFame>> GetHallOfFamesAsync(int ModuleId)
|
||||
@@ -111,5 +117,104 @@ namespace SZUAbsolventenverein.Module.HallOfFame.Services
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task ReportAsync(int HallOfFameId, int ModuleId, string reason)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||
{
|
||||
var report = new Models.HallOfFameReport
|
||||
{
|
||||
HallOfFameId = HallOfFameId,
|
||||
Reason = reason
|
||||
};
|
||||
_HallOfFameRepository.AddHallOfFameReport(report);
|
||||
|
||||
var hallOfFame = _HallOfFameRepository.GetHallOfFame(HallOfFameId);
|
||||
if (hallOfFame != null && !hallOfFame.IsReported)
|
||||
{
|
||||
hallOfFame.IsReported = true;
|
||||
_HallOfFameRepository.UpdateHallOfFame(hallOfFame);
|
||||
}
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "HallOfFame Reported {HallOfFameId}", HallOfFameId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Report Attempt {HallOfFameId} {ModuleId}", HallOfFameId, ModuleId);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<List<Models.HallOfFameReport>> GetHallOfFameReportsAsync(int HallOfFameId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
return Task.FromResult(_HallOfFameRepository.GetHallOfFameReports(HallOfFameId).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Get Reports Attempt {HallOfFameId} {ModuleId}", HallOfFameId, ModuleId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task DeleteHallOfFameReportAsync(int HallOfFameReportId, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
var report = _HallOfFameRepository.GetHallOfFameReport(HallOfFameReportId);
|
||||
if (report != null)
|
||||
{
|
||||
int hallOfFameId = report.HallOfFameId;
|
||||
_HallOfFameRepository.DeleteHallOfFameReport(HallOfFameReportId);
|
||||
|
||||
// Check if there are any reports left for this entry
|
||||
var remainingReports = _HallOfFameRepository.GetHallOfFameReports(hallOfFameId);
|
||||
if (!remainingReports.Any())
|
||||
{
|
||||
var hallOfFame = _HallOfFameRepository.GetHallOfFame(hallOfFameId);
|
||||
if (hallOfFame != null)
|
||||
{
|
||||
hallOfFame.IsReported = false;
|
||||
_HallOfFameRepository.UpdateHallOfFame(hallOfFame);
|
||||
}
|
||||
}
|
||||
}
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "HallOfFame Report Deleted {HallOfFameReportId}", HallOfFameReportId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized HallOfFame Delete Report Attempt {HallOfFameReportId} {ModuleId}", HallOfFameReportId, ModuleId);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public async Task<string> UploadFileAsync(Stream stream, string fileName, int ModuleId)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
var extension = Path.GetExtension(fileName).ToLower();
|
||||
|
||||
if (extension != ".jpg" && extension != ".jpeg" && extension != ".png")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var folder = Path.Combine(_environment.WebRootPath, "Content", "HallOfFame");
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
|
||||
var newFileName = Guid.NewGuid().ToString() + extension;
|
||||
var path = Path.Combine(folder, newFileName);
|
||||
|
||||
using (var fileStream = new FileStream(path, FileMode.Create))
|
||||
{
|
||||
await stream.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
return "/Content/HallOfFame/" + newFileName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user