Added database stuff for plesk servers
This commit is contained in:
@@ -42,6 +42,7 @@ public class DataContext : DbContext
|
||||
public DbSet<AaPanel> AaPanels { get; set; }
|
||||
public DbSet<Website> Websites { get; set; }
|
||||
public DbSet<DdosAttack> DdosAttacks { get; set; }
|
||||
public DbSet<PleskServer> PleskServers { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
|
||||
8
Moonlight/App/Database/Entities/PleskServer.cs
Normal file
8
Moonlight/App/Database/Entities/PleskServer.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Moonlight.App.Database.Entities;
|
||||
|
||||
public class PleskServer
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string BaseUrl { get; set; } = "";
|
||||
public string ApiKey { get; set; } = "";
|
||||
}
|
||||
1085
Moonlight/App/Database/Migrations/20230322091250_AddedPleskServer.Designer.cs
generated
Normal file
1085
Moonlight/App/Database/Migrations/20230322091250_AddedPleskServer.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Moonlight.App.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddedPleskServer : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PleskServers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
BaseUrl = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
ApiKey = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PleskServers", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PleskServers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,6 +446,25 @@ namespace Moonlight.App.Database.Migrations
|
||||
b.ToTable("NotificationClients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Moonlight.App.Database.Entities.PleskServer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ApiKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("BaseUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("PleskServers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Moonlight.App.Database.Entities.Revoke", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
||||
44
Moonlight/App/Repositories/PleskServerRepository.cs
Normal file
44
Moonlight/App/Repositories/PleskServerRepository.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moonlight.App.Database;
|
||||
using Moonlight.App.Database.Entities;
|
||||
|
||||
namespace Moonlight.App.Repositories;
|
||||
|
||||
public class PleskServerRepository : IDisposable
|
||||
{
|
||||
private readonly DataContext DataContext;
|
||||
|
||||
public PleskServerRepository(DataContext dataContext)
|
||||
{
|
||||
DataContext = dataContext;
|
||||
}
|
||||
|
||||
public DbSet<PleskServer> Get()
|
||||
{
|
||||
return DataContext.PleskServers;
|
||||
}
|
||||
|
||||
public PleskServer Add(PleskServer pleskServer)
|
||||
{
|
||||
var x = DataContext.PleskServers.Add(pleskServer);
|
||||
DataContext.SaveChanges();
|
||||
return x.Entity;
|
||||
}
|
||||
|
||||
public void Update(PleskServer pleskServer)
|
||||
{
|
||||
DataContext.PleskServers.Update(pleskServer);
|
||||
DataContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void Delete(PleskServer pleskServer)
|
||||
{
|
||||
DataContext.PleskServers.Remove(pleskServer);
|
||||
DataContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DataContext.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ namespace Moonlight
|
||||
builder.Services.AddScoped<AaPanelRepository>();
|
||||
builder.Services.AddScoped<WebsiteRepository>();
|
||||
builder.Services.AddScoped<DdosAttackRepository>();
|
||||
builder.Services.AddScoped<PleskServerRepository>();
|
||||
|
||||
builder.Services.AddScoped<AuditLogEntryRepository>();
|
||||
builder.Services.AddScoped<ErrorLogEntryRepository>();
|
||||
|
||||
Reference in New Issue
Block a user