New: DB-Migration / Repositories und Models für den Premiumbereich
This commit is contained in:
@@ -9,9 +9,9 @@ namespace SZUAbsolventenverein.Module.PremiumArea
|
|||||||
{
|
{
|
||||||
Name = "PremiumArea",
|
Name = "PremiumArea",
|
||||||
Description = "This module adds a premium member system to Octane. Users receive premium status after completing a payment. Premium members get access to exclusive features and content.",
|
Description = "This module adds a premium member system to Octane. Users receive premium status after completing a payment. Premium members get access to exclusive features and content.",
|
||||||
Version = "1.0.0",
|
Version = "1.0.2",
|
||||||
ServerManagerType = "SZUAbsolventenverein.Module.PremiumArea.Manager.PremiumAreaManager, SZUAbsolventenverein.Module.PremiumArea.Server.Oqtane",
|
ServerManagerType = "SZUAbsolventenverein.Module.PremiumArea.Manager.PremiumAreaManager, SZUAbsolventenverein.Module.PremiumArea.Server.Oqtane",
|
||||||
ReleaseVersions = "1.0.0",
|
ReleaseVersions = "1.0.0,1.0.1,1.0.2",
|
||||||
Dependencies = "SZUAbsolventenverein.Module.PremiumArea.Shared.Oqtane",
|
Dependencies = "SZUAbsolventenverein.Module.PremiumArea.Shared.Oqtane",
|
||||||
PackageName = "SZUAbsolventenverein.Module.PremiumArea"
|
PackageName = "SZUAbsolventenverein.Module.PremiumArea"
|
||||||
};
|
};
|
||||||
|
|||||||
59
Server/Controllers/UserContactController.cs
Normal file
59
Server/Controllers/UserContactController.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
using Oqtane.Enums;
|
||||||
|
using Oqtane.Infrastructure;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Services;
|
||||||
|
using Oqtane.Controllers;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Controllers
|
||||||
|
{
|
||||||
|
[Route(ControllerRoutes.ApiRoute)]
|
||||||
|
public class UserContactController : ModuleControllerBase
|
||||||
|
{
|
||||||
|
private readonly IUserContactService _service;
|
||||||
|
|
||||||
|
public UserContactController(IUserContactService service, ILogManager logger, IHttpContextAccessor accessor) : base(logger, accessor)
|
||||||
|
{
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/<controller>/search/query?moduleid=x
|
||||||
|
[HttpGet("search/{query}")]
|
||||||
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||||
|
public async Task<IEnumerable<User>> Search(string query, string moduleid)
|
||||||
|
{
|
||||||
|
int ModuleId;
|
||||||
|
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
|
||||||
|
{
|
||||||
|
return await _service.SearchUsersAsync(query, ModuleId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/<controller>/send
|
||||||
|
[HttpPost("send")]
|
||||||
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||||
|
public async Task Send(int recipientId, string message, string moduleid)
|
||||||
|
{
|
||||||
|
int ModuleId;
|
||||||
|
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
|
||||||
|
{
|
||||||
|
await _service.SendMessageAsync(recipientId, message, ModuleId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Server/Migrations/01000001_AddPremiumTables.cs
Normal file
42
Server/Migrations/01000001_AddPremiumTables.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Oqtane.Databases.Interfaces;
|
||||||
|
using Oqtane.Migrations;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Migrations.EntityBuilders;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Repository;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PremiumAreaContext))]
|
||||||
|
[Migration("SZUAbsolventenverein.Module.PremiumArea.01.00.00.01")]
|
||||||
|
public class AddPremiumTables : MultiDatabaseMigration
|
||||||
|
{
|
||||||
|
public AddPremiumTables(IDatabase database) : base(database)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
var engAppBuilder = new EngineerApplicationEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
engAppBuilder.Create();
|
||||||
|
|
||||||
|
var userPremBuilder = new UserPremiumEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
userPremBuilder.Create();
|
||||||
|
|
||||||
|
var premEventBuilder = new PremiumEventEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
premEventBuilder.Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
var engAppBuilder = new EngineerApplicationEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
engAppBuilder.Drop();
|
||||||
|
|
||||||
|
var userPremBuilder = new UserPremiumEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
userPremBuilder.Drop();
|
||||||
|
|
||||||
|
var premEventBuilder = new PremiumEventEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||||
|
premEventBuilder.Drop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
90
Server/Migrations/01000002_AddReportAndFileColumns.cs
Normal file
90
Server/Migrations/01000002_AddReportAndFileColumns.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Oqtane.Databases.Interfaces;
|
||||||
|
using Oqtane.Migrations;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Migrations.EntityBuilders;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Repository;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PremiumAreaContext))]
|
||||||
|
[Migration("SZUAbsolventenverein.Module.PremiumArea.01.00.00.02")]
|
||||||
|
public class AddReportAndFileColumns : MultiDatabaseMigration
|
||||||
|
{
|
||||||
|
public AddReportAndFileColumns(IDatabase database) : base(database)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
// Add FileId (nullable int) - assuming missing
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "FileId",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
// Add PdfFileName (string 256)
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "PdfFileName",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
maxLength: 256,
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
// Add ApprovedOn (DateTime nullable) - might exist but adding if missing?
|
||||||
|
// MigrationBuilder will fail if exists. We assume schema drift needs this.
|
||||||
|
// If it exists, user must handle.
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "ApprovedOn",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
// Add IsReported (bool not null default false)
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IsReported",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
|
||||||
|
// Add ReportReason (string max nullable)
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "ReportReason",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
// Add ReportCount (int not null default 0)
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "ReportCount",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IsReported",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ReportReason",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ReportCount",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "FileId",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "PdfFileName",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ApprovedOn",
|
||||||
|
table: "SZUAbsolventenvereinEngineerApplications");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||||
|
using Oqtane.Databases.Interfaces;
|
||||||
|
using Oqtane.Migrations;
|
||||||
|
using Oqtane.Migrations.EntityBuilders;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Migrations.EntityBuilders
|
||||||
|
{
|
||||||
|
public class EngineerApplicationEntityBuilder : AuditableBaseEntityBuilder<EngineerApplicationEntityBuilder>
|
||||||
|
{
|
||||||
|
private const string _entityTableName = "SZUAbsolventenvereinEngineerApplications";
|
||||||
|
private readonly PrimaryKey<EngineerApplicationEntityBuilder> _primaryKey = new("PK_SZUAbsolventenvereinEngineerApplications", x => x.ApplicationId);
|
||||||
|
private readonly ForeignKey<EngineerApplicationEntityBuilder> _moduleForeignKey = new("FK_SZUAbsolventenvereinEngineerApplications_Module", x => x.ModuleId, "Module", "ModuleId", ReferentialAction.Cascade);
|
||||||
|
|
||||||
|
public EngineerApplicationEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
|
||||||
|
{
|
||||||
|
EntityTableName = _entityTableName;
|
||||||
|
PrimaryKey = _primaryKey;
|
||||||
|
ForeignKeys.Add(_moduleForeignKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override EngineerApplicationEntityBuilder BuildTable(ColumnsBuilder table)
|
||||||
|
{
|
||||||
|
ApplicationId = AddAutoIncrementColumn(table, "ApplicationId");
|
||||||
|
UserId = AddIntegerColumn(table, "UserId");
|
||||||
|
ModuleId = AddIntegerColumn(table, "ModuleId");
|
||||||
|
FileId = AddIntegerColumn(table, "FileId", true);
|
||||||
|
PdfFileName = AddStringColumn(table, "PdfFileName", 256);
|
||||||
|
Status = AddStringColumn(table, "Status", 50);
|
||||||
|
AdminReviewedBy = AddIntegerColumn(table, "AdminReviewedBy", true);
|
||||||
|
AdminReviewedAt = AddDateTimeColumn(table, "AdminReviewedAt", true);
|
||||||
|
AdminNote = AddMaxStringColumn(table, "AdminNote");
|
||||||
|
SubmittedOn = AddDateTimeColumn(table, "SubmittedOn", true);
|
||||||
|
ApprovedOn = AddDateTimeColumn(table, "ApprovedOn", true);
|
||||||
|
IsReported = AddBooleanColumn(table, "IsReported", false);
|
||||||
|
ReportReason = AddMaxStringColumn(table, "ReportReason", true);
|
||||||
|
ReportCount = AddIntegerColumn(table, "ReportCount", false);
|
||||||
|
AddAuditableColumns(table);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public OperationBuilder<AddColumnOperation> ApplicationId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> UserId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> ModuleId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> FileId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> PdfFileName { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> Status { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> AdminReviewedBy { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> AdminReviewedAt { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> AdminNote { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> SubmittedOn { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> ApprovedOn { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> IsReported { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> ReportReason { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> ReportCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||||
|
using Oqtane.Databases.Interfaces;
|
||||||
|
using Oqtane.Migrations;
|
||||||
|
using Oqtane.Migrations.EntityBuilders;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Migrations.EntityBuilders
|
||||||
|
{
|
||||||
|
public class PremiumEventEntityBuilder : AuditableBaseEntityBuilder<PremiumEventEntityBuilder>
|
||||||
|
{
|
||||||
|
private const string _entityTableName = "SZUAbsolventenvereinPremiumEvents";
|
||||||
|
private readonly PrimaryKey<PremiumEventEntityBuilder> _primaryKey = new("PK_SZUAbsolventenvereinPremiumEvents", x => x.Id);
|
||||||
|
|
||||||
|
public PremiumEventEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
|
||||||
|
{
|
||||||
|
EntityTableName = _entityTableName;
|
||||||
|
PrimaryKey = _primaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override PremiumEventEntityBuilder BuildTable(ColumnsBuilder table)
|
||||||
|
{
|
||||||
|
Id = AddAutoIncrementColumn(table, "Id");
|
||||||
|
UserId = AddIntegerColumn(table, "UserId");
|
||||||
|
DeltaDays = AddIntegerColumn(table, "DeltaDays");
|
||||||
|
Source = AddStringColumn(table, "Source", 50);
|
||||||
|
ReferenceId = AddMaxStringColumn(table, "ReferenceId");
|
||||||
|
AddAuditableColumns(table);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationBuilder<AddColumnOperation> Id { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> UserId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> DeltaDays { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> Source { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> ReferenceId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Server/Migrations/EntityBuilders/UserPremiumEntityBuilder.cs
Normal file
36
Server/Migrations/EntityBuilders/UserPremiumEntityBuilder.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders;
|
||||||
|
using Oqtane.Databases.Interfaces;
|
||||||
|
using Oqtane.Migrations;
|
||||||
|
using Oqtane.Migrations.EntityBuilders;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Migrations.EntityBuilders
|
||||||
|
{
|
||||||
|
public class UserPremiumEntityBuilder : AuditableBaseEntityBuilder<UserPremiumEntityBuilder>
|
||||||
|
{
|
||||||
|
private const string _entityTableName = "SZUAbsolventenvereinUserPremium";
|
||||||
|
private readonly PrimaryKey<UserPremiumEntityBuilder> _primaryKey = new("PK_SZUAbsolventenvereinUserPremium", x => x.Id);
|
||||||
|
|
||||||
|
public UserPremiumEntityBuilder(MigrationBuilder migrationBuilder, IDatabase database) : base(migrationBuilder, database)
|
||||||
|
{
|
||||||
|
EntityTableName = _entityTableName;
|
||||||
|
PrimaryKey = _primaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override UserPremiumEntityBuilder BuildTable(ColumnsBuilder table)
|
||||||
|
{
|
||||||
|
Id = AddAutoIncrementColumn(table, "Id");
|
||||||
|
UserId = AddIntegerColumn(table, "UserId");
|
||||||
|
PremiumUntil = AddDateTimeColumn(table, "PremiumUntil", true);
|
||||||
|
Source = AddStringColumn(table, "Source", 50);
|
||||||
|
AddAuditableColumns(table);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationBuilder<AddColumnOperation> Id { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> UserId { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> PremiumUntil { get; set; }
|
||||||
|
public OperationBuilder<AddColumnOperation> Source { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
83
Server/Repository/EngineerApplicationRepository.cs
Normal file
83
Server/Repository/EngineerApplicationRepository.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||||
|
{
|
||||||
|
public interface IEngineerApplicationRepository
|
||||||
|
{
|
||||||
|
IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId);
|
||||||
|
IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId, string status);
|
||||||
|
EngineerApplication GetEngineerApplication(int ApplicationId);
|
||||||
|
EngineerApplication GetEngineerApplication(int ApplicationId, bool tracking);
|
||||||
|
EngineerApplication AddEngineerApplication(EngineerApplication EngineerApplication);
|
||||||
|
EngineerApplication UpdateEngineerApplication(EngineerApplication EngineerApplication);
|
||||||
|
void DeleteEngineerApplication(int ApplicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EngineerApplicationRepository : IEngineerApplicationRepository, ITransientService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<PremiumAreaContext> _factory;
|
||||||
|
|
||||||
|
public EngineerApplicationRepository(IDbContextFactory<PremiumAreaContext> factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
return db.EngineerApplication.Where(item => item.ModuleId == ModuleId).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<EngineerApplication> GetEngineerApplications(int ModuleId, string status)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
return db.EngineerApplication.Where(item => item.ModuleId == ModuleId && item.Status == status).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EngineerApplication GetEngineerApplication(int ApplicationId)
|
||||||
|
{
|
||||||
|
return GetEngineerApplication(ApplicationId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EngineerApplication GetEngineerApplication(int ApplicationId, bool tracking)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
if (tracking)
|
||||||
|
{
|
||||||
|
return db.EngineerApplication.Find(ApplicationId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return db.EngineerApplication.AsNoTracking().FirstOrDefault(item => item.ApplicationId == ApplicationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public EngineerApplication AddEngineerApplication(EngineerApplication EngineerApplication)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
db.EngineerApplication.Add(EngineerApplication);
|
||||||
|
db.SaveChanges();
|
||||||
|
return EngineerApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EngineerApplication UpdateEngineerApplication(EngineerApplication EngineerApplication)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
db.Entry(EngineerApplication).State = EntityState.Modified;
|
||||||
|
db.SaveChanges();
|
||||||
|
return EngineerApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteEngineerApplication(int ApplicationId)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
EngineerApplication EngineerApplication = db.EngineerApplication.Find(ApplicationId);
|
||||||
|
db.EngineerApplication.Remove(EngineerApplication);
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
|||||||
public class PremiumAreaContext : DBContextBase, ITransientService, IMultiDatabase
|
public class PremiumAreaContext : DBContextBase, ITransientService, IMultiDatabase
|
||||||
{
|
{
|
||||||
public virtual DbSet<Models.PremiumArea> PremiumArea { get; set; }
|
public virtual DbSet<Models.PremiumArea> PremiumArea { get; set; }
|
||||||
|
public virtual DbSet<Models.EngineerApplication> EngineerApplication { get; set; }
|
||||||
|
public virtual DbSet<Models.UserPremium> UserPremium { get; set; }
|
||||||
|
public virtual DbSet<Models.PremiumEvent> PremiumEvent { get; set; }
|
||||||
|
|
||||||
public PremiumAreaContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
|
public PremiumAreaContext(IDBContextDependencies DBContextDependencies) : base(DBContextDependencies)
|
||||||
{
|
{
|
||||||
@@ -21,6 +24,9 @@ namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
|||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
|
|
||||||
builder.Entity<Models.PremiumArea>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinPremiumArea"));
|
builder.Entity<Models.PremiumArea>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinPremiumArea"));
|
||||||
|
builder.Entity<Models.EngineerApplication>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinEngineerApplications"));
|
||||||
|
builder.Entity<Models.UserPremium>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinUserPremium"));
|
||||||
|
builder.Entity<Models.PremiumEvent>().ToTable(ActiveDatabase.RewriteName("SZUAbsolventenvereinPremiumEvents"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
60
Server/Repository/UserPremiumRepository.cs
Normal file
60
Server/Repository/UserPremiumRepository.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
using SZUAbsolventenverein.Module.PremiumArea.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Repository
|
||||||
|
{
|
||||||
|
public interface IUserPremiumRepository
|
||||||
|
{
|
||||||
|
UserPremium GetUserPremium(int UserId);
|
||||||
|
UserPremium SaveUserPremium(UserPremium UserPremium);
|
||||||
|
void AddPremiumEvent(PremiumEvent premiumEvent);
|
||||||
|
IEnumerable<PremiumEvent> GetPremiumEvents(int UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserPremiumRepository : IUserPremiumRepository, ITransientService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<PremiumAreaContext> _factory;
|
||||||
|
|
||||||
|
public UserPremiumRepository(IDbContextFactory<PremiumAreaContext> factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserPremium GetUserPremium(int UserId)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
return db.UserPremium.FirstOrDefault(item => item.UserId == UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserPremium SaveUserPremium(UserPremium UserPremium)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
if (UserPremium.Id > 0)
|
||||||
|
{
|
||||||
|
db.Entry(UserPremium).State = EntityState.Modified;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
db.UserPremium.Add(UserPremium);
|
||||||
|
}
|
||||||
|
db.SaveChanges();
|
||||||
|
return UserPremium;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddPremiumEvent(PremiumEvent premiumEvent)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
db.PremiumEvent.Add(premiumEvent);
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<PremiumEvent> GetPremiumEvents(int UserId)
|
||||||
|
{
|
||||||
|
using var db = _factory.CreateDbContext();
|
||||||
|
return db.PremiumEvent.Where(item => item.UserId == UserId).OrderByDescending(x => x.CreatedOn).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
Shared/Models/EngineerApplication.cs
Normal file
37
Shared/Models/EngineerApplication.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Models
|
||||||
|
{
|
||||||
|
[Table("SZUAbsolventenvereinEngineerApplications")]
|
||||||
|
public class EngineerApplication : ModelBase
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int ApplicationId { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
|
public int ModuleId { get; set; } // Context context
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int? FileId { get; set; }
|
||||||
|
|
||||||
|
[StringLength(256)]
|
||||||
|
public string PdfFileName { get; set; }
|
||||||
|
|
||||||
|
public bool IsReported { get; set; }
|
||||||
|
public string ReportReason { get; set; }
|
||||||
|
public int ReportCount { get; set; }
|
||||||
|
|
||||||
|
// Status: "Draft", "Submitted", "Approved", "Rejected"
|
||||||
|
[StringLength(50)]
|
||||||
|
public string Status { get; set; }
|
||||||
|
|
||||||
|
public int? AdminReviewedBy { get; set; }
|
||||||
|
public DateTime? AdminReviewedAt { get; set; }
|
||||||
|
public string AdminNote { get; set; }
|
||||||
|
|
||||||
|
public DateTime? SubmittedOn { get; set; }
|
||||||
|
public DateTime? ApprovedOn { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Shared/Models/PremiumEvent.cs
Normal file
23
Shared/Models/PremiumEvent.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Models
|
||||||
|
{
|
||||||
|
[Table("SZUAbsolventenvereinPremiumEvents")]
|
||||||
|
public class PremiumEvent : ModelBase
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
public int DeltaDays { get; set; } // +365, etc.
|
||||||
|
|
||||||
|
[StringLength(50)]
|
||||||
|
public string Source { get; set; }
|
||||||
|
|
||||||
|
public string ReferenceId { get; set; } // e.g. "AppId:12"
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Shared/Models/UserPremium.cs
Normal file
21
Shared/Models/UserPremium.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace SZUAbsolventenverein.Module.PremiumArea.Models
|
||||||
|
{
|
||||||
|
[Table("SZUAbsolventenvereinUserPremium")]
|
||||||
|
public class UserPremium : ModelBase
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
public DateTime? PremiumUntil { get; set; }
|
||||||
|
|
||||||
|
[StringLength(50)]
|
||||||
|
public string Source { get; set; } // "paid", "promo_engineer_application", "admin"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user