Completata aggiunta primi elementi gestione area admin
This commit is contained in:
@@ -8,6 +8,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagMan.Data.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Classe amministrazione Db principale:
|
||||
/// - creazione utenti sul Server MySql
|
||||
/// - gestione DB/Tabele x identity & gestione multi-tenant
|
||||
/// </summary>
|
||||
public class DbAdmin : IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
@@ -26,10 +31,10 @@ namespace MagMan.Data.Admin
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static bool checkCreateUser(string username, string pwd, string dbName)
|
||||
public static bool CheckCreateUser(string username, string pwd, string dbName)
|
||||
{
|
||||
bool answ = false;
|
||||
using (DbAdminContext adbCtx = new DbAdminContext())
|
||||
using (ServerAdminContext adbCtx = new ServerAdminContext())
|
||||
{
|
||||
// ricerca utente...
|
||||
var numUser = adbCtx
|
||||
@@ -57,7 +62,7 @@ namespace MagMan.Data.Admin
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task<bool> migrateDbIdentity()
|
||||
public static async Task<bool> MigrateDbIdentity()
|
||||
{
|
||||
bool answ = false;
|
||||
using (IdentityContext dbCtx = new IdentityContext())
|
||||
@@ -67,7 +72,17 @@ namespace MagMan.Data.Admin
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task<bool> MigrateDbMultiTenant()
|
||||
{
|
||||
bool answ = false;
|
||||
using (MultiTenantContext dbCtx = new MultiTenantContext())
|
||||
{
|
||||
await dbCtx.Database.MigrateAsync();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,13 +42,20 @@ namespace MagMan.Data.Admin
|
||||
public static bool CheckUser(string nKey, string sKey)
|
||||
{
|
||||
// esecuzione script di install locale
|
||||
return DbAdmin.checkCreateUser(DATABASE_USER, DATABASE_PWD, DATABASE_NAME);
|
||||
return DbAdmin.CheckCreateUser(DATABASE_USER, DATABASE_PWD, DATABASE_NAME);
|
||||
}
|
||||
|
||||
public static bool ExecMigrationIdentity()
|
||||
{
|
||||
// esecuzione migrazione
|
||||
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbIdentity());
|
||||
var migrateTask = Task.Run(async () => await DbAdmin.MigrateDbIdentity());
|
||||
migrateTask.Wait();
|
||||
return migrateTask.Result;
|
||||
}
|
||||
public static bool ExecMigrationMultiTenant()
|
||||
{
|
||||
// esecuzione migrazione
|
||||
var migrateTask = Task.Run(async () => await DbAdmin.MigrateDbMultiTenant());
|
||||
migrateTask.Wait();
|
||||
return migrateTask.Result;
|
||||
}
|
||||
@@ -58,9 +65,8 @@ namespace MagMan.Data.Admin
|
||||
DATABASE_SERV = server;
|
||||
// tutto fisso x gestione utenti
|
||||
CONNECTION_STRING = $"Server={DATABASE_SERV};port=3306;database={DATABASE_NAME};uid={DATABASE_USER};pwd={DATABASE_PWD};sslmode=None;";
|
||||
// stringa admin con utente root egalware...
|
||||
// stringa admin con utente admin dell'applicazione (già creato)...
|
||||
ADMIN_CONNECTION_STRING = $"Server={DATABASE_SERV};port=3306;database=mysql;uid={DATABASE_USER};pwd={DATABASE_PWD};sslmode=None;";
|
||||
//ADMIN_CONNECTION_STRING = $"server={DATABASE_SERV};port=3306;database=mysql;uid=root;pwd=Egalware_24068!;sslmode=None";
|
||||
}
|
||||
|
||||
public static ServerVersion MysqlServerVersion(string connString)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagMan.Data.Admin.DbModels
|
||||
{
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
[Table("AuthKeyList")]
|
||||
public partial class AuthKeyModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary Key AUTO
|
||||
/// </summary>
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int MachineID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ext ref Customers
|
||||
/// </summary>
|
||||
public int CustomerID { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Nome
|
||||
/// </summary>
|
||||
public string KeyName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Nome
|
||||
/// </summary>
|
||||
public string KeyValue { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Note/Descrizione
|
||||
/// </summary>
|
||||
public string Note { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Navigation property to Customer
|
||||
/// </summary>
|
||||
[ForeignKey("CustomerID")]
|
||||
public virtual CustomerModel CustomerNav { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagMan.Data.Admin.DbModels
|
||||
{
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
[Table("CustomerList")]
|
||||
public partial class CustomerModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary Key AUTO
|
||||
/// </summary>
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int CustomerID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nome
|
||||
/// </summary>
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Note/Descrizione
|
||||
/// </summary>
|
||||
public string Note { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Check attivo
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// DateTime Attivazione
|
||||
/// </summary>
|
||||
public DateTime DtActivation { get; set; } = DateTime.Today;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagMan.Data.Admin.DbModels
|
||||
{
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
[Table("MachineList")]
|
||||
public partial class MachineModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Primary Key AUTO
|
||||
/// </summary>
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int MachineID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ext ref Customers
|
||||
/// </summary>
|
||||
public int CustomerID { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Nome
|
||||
/// </summary>
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Note/Descrizione
|
||||
/// </summary>
|
||||
public string Note { get; set; } = "";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Navigation property to Customer
|
||||
/// </summary>
|
||||
[ForeignKey("CustomerID")]
|
||||
public virtual CustomerModel CustomerNav { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace MagMan.Data.Admin
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public virtual DbSet<TableCount> DbSetCounts { get; set; }
|
||||
public virtual DbSet<TableCount> DbSetCounts { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MagMan.Data.Admin;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MagMan.Data.Admin.Migrations
|
||||
{
|
||||
[DbContext(typeof(MultiTenantContext))]
|
||||
[Migration("20240111160917_MultiTenantInitDb")]
|
||||
partial class MultiTenantInitDb
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.25")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.AuthKeyModel", b =>
|
||||
{
|
||||
b.Property<int>("MachineID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CustomerID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("KeyName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("KeyValue")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("MachineID");
|
||||
|
||||
b.HasIndex("CustomerID");
|
||||
|
||||
b.ToTable("AuthKeyList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.CustomerModel", b =>
|
||||
{
|
||||
b.Property<int>("CustomerID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DtActivation")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("CustomerID");
|
||||
|
||||
b.ToTable("CustomerList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.MachineModel", b =>
|
||||
{
|
||||
b.Property<int>("MachineID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CustomerID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("MachineID");
|
||||
|
||||
b.HasIndex("CustomerID");
|
||||
|
||||
b.ToTable("MachineList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.AuthKeyModel", b =>
|
||||
{
|
||||
b.HasOne("MagMan.Data.Admin.DbModels.CustomerModel", "CustomerNav")
|
||||
.WithMany()
|
||||
.HasForeignKey("CustomerID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CustomerNav");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.MachineModel", b =>
|
||||
{
|
||||
b.HasOne("MagMan.Data.Admin.DbModels.CustomerModel", "CustomerNav")
|
||||
.WithMany()
|
||||
.HasForeignKey("CustomerID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CustomerNav");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MagMan.Data.Admin.Migrations
|
||||
{
|
||||
public partial class MultiTenantInitDb : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CustomerList",
|
||||
columns: table => new
|
||||
{
|
||||
CustomerID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Note = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
DtActivation = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CustomerList", x => x.CustomerID);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AuthKeyList",
|
||||
columns: table => new
|
||||
{
|
||||
MachineID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
CustomerID = table.Column<int>(type: "int", nullable: false),
|
||||
KeyName = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
KeyValue = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Note = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AuthKeyList", x => x.MachineID);
|
||||
table.ForeignKey(
|
||||
name: "FK_AuthKeyList_CustomerList_CustomerID",
|
||||
column: x => x.CustomerID,
|
||||
principalTable: "CustomerList",
|
||||
principalColumn: "CustomerID",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "MachineList",
|
||||
columns: table => new
|
||||
{
|
||||
MachineID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
CustomerID = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
Note = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_MachineList", x => x.MachineID);
|
||||
table.ForeignKey(
|
||||
name: "FK_MachineList_CustomerList_CustomerID",
|
||||
column: x => x.CustomerID,
|
||||
principalTable: "CustomerList",
|
||||
principalColumn: "CustomerID",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AuthKeyList_CustomerID",
|
||||
table: "AuthKeyList",
|
||||
column: "CustomerID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_MachineList_CustomerID",
|
||||
table: "MachineList",
|
||||
column: "CustomerID");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AuthKeyList");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "MachineList");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "CustomerList");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MagMan.Data.Admin;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MagMan.Data.Admin.Migrations
|
||||
{
|
||||
[DbContext(typeof(MultiTenantContext))]
|
||||
partial class MultiTenantContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.25")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.AuthKeyModel", b =>
|
||||
{
|
||||
b.Property<int>("MachineID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CustomerID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("KeyName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("KeyValue")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("MachineID");
|
||||
|
||||
b.HasIndex("CustomerID");
|
||||
|
||||
b.ToTable("AuthKeyList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.CustomerModel", b =>
|
||||
{
|
||||
b.Property<int>("CustomerID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DtActivation")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("CustomerID");
|
||||
|
||||
b.ToTable("CustomerList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.MachineModel", b =>
|
||||
{
|
||||
b.Property<int>("MachineID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CustomerID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("MachineID");
|
||||
|
||||
b.HasIndex("CustomerID");
|
||||
|
||||
b.ToTable("MachineList");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.AuthKeyModel", b =>
|
||||
{
|
||||
b.HasOne("MagMan.Data.Admin.DbModels.CustomerModel", "CustomerNav")
|
||||
.WithMany()
|
||||
.HasForeignKey("CustomerID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CustomerNav");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MagMan.Data.Admin.DbModels.MachineModel", b =>
|
||||
{
|
||||
b.HasOne("MagMan.Data.Admin.DbModels.CustomerModel", "CustomerNav")
|
||||
.WithMany()
|
||||
.HasForeignKey("CustomerID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("CustomerNav");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace MagMan.Data.Admin
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Estensione per seed iniziale dei dati nel DB
|
||||
/// Estensione per seed iniziale dei dati nel DB (auth)
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder"></param>
|
||||
public static void Seed(this ModelBuilder modelBuilder)
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
using MagMan.Data.Admin.DbModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagMan.Data.Admin
|
||||
{
|
||||
public partial class MultiTenantContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MultiTenantContext()
|
||||
{
|
||||
}
|
||||
|
||||
public MultiTenantContext(DbContextOptions<MultiTenantContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
|
||||
public virtual DbSet<CustomerModel> DbSetCustomers { get; set; } = null!;
|
||||
public virtual DbSet<MachineModel> DbSetMachines { get; set; } = null!;
|
||||
public virtual DbSet<AuthKeyModel> DbSetAuthKey { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
// default
|
||||
string connString = DbConfig.CONNECTION_STRING;
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
#if DEBUG
|
||||
connString = "Server=localhost;port=3306;database=MagMan_Admin;uid=MagMan_DbUser;pwd=viad@nte16!;sslmode=None;";
|
||||
#endif
|
||||
var serverVersion = ServerVersion.AutoDetect(connString);
|
||||
optionsBuilder.UseMySql(connString, serverVersion);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
|
||||
{
|
||||
relationship.DeleteBehavior = DeleteBehavior.Restrict;
|
||||
}
|
||||
|
||||
#if false
|
||||
modelBuilder.Entity<ConfigModel>(entity =>
|
||||
{
|
||||
entity.Property(e => e.ValStd)
|
||||
.HasComment("Valore di default/riferimento per la variabile");
|
||||
});
|
||||
modelBuilder.Entity<ListValModel>().HasKey(c => new { c.TabName, c.FieldName, c.Val });
|
||||
modelBuilder.Seed();
|
||||
#endif
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void DbForceMigrate()
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
Log.Info("MultiTenantContext DbForceMigrate: done!");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "MultiTenantContext DbForceMigrate: Exception during context initialization 01");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -6,30 +6,27 @@ using Microsoft.Extensions.Configuration;
|
||||
namespace MagMan.Data.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Classe gestione admin generale MySql:
|
||||
/// Classe gestione Server MySql:
|
||||
/// - creazione utenti su DB principale
|
||||
/// - aggiunta permessi lettura/scrittura
|
||||
/// </summary>
|
||||
public partial class DbAdminContext : DbContext
|
||||
public partial class ServerAdminContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public DbAdminContext()
|
||||
public ServerAdminContext()
|
||||
{
|
||||
}
|
||||
|
||||
public DbAdminContext(IConfiguration configuration)
|
||||
public ServerAdminContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public DbAdminContext(DbContextOptions<DbAdminContext> options) : base(options)
|
||||
public ServerAdminContext(DbContextOptions<ServerAdminContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,7 +37,7 @@ namespace MagMan.Data.Admin
|
||||
/// <summary>
|
||||
/// User management
|
||||
/// </summary>
|
||||
public virtual DbSet<UserPriv> UserList { get; set; }
|
||||
public virtual DbSet<UserPriv> UserList { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
@@ -48,10 +45,10 @@ namespace MagMan.Data.Admin
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connString = DbConfig.ADMIN_CONNECTION_STRING;
|
||||
string connString = "";
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
//connString = _configuration.GetConnectionString("MagMan.Data");
|
||||
// chiave cablata x gestione Server
|
||||
connString = "Server=localhost;port=3306;database=mysql;user=root;pwd=Egalware_24068!;sslmode=None;";
|
||||
var serverVersion = ServerVersion.AutoDetect(connString);
|
||||
optionsBuilder.UseMySql(connString, serverVersion);
|
||||
@@ -61,17 +58,19 @@ namespace MagMan.Data.Admin
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UserPriv>().HasKey(c => new { c.Host, c.User });
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagMan.UI", "MagMan.UI\MagM
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagMan.Core", "MagMan.Core\MagMan.Core.csproj", "{328950E0-CCFB-40EF-AC68-A26912135588}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagMan.Data.Tenant", "MagMan.Data.Tenant\MagMan.Data.Tenant.csproj", "{69E22B67-FFA7-4E21-81A7-B8F025A420C5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagMan.Data.Tenant", "MagMan.Data.Tenant\MagMan.Data.Tenant.csproj", "{69E22B67-FFA7-4E21-81A7-B8F025A420C5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagMan.Data.Admin", "MagMan.Data.Admin\MagMan.Data.Admin.csproj", "{324914D5-2616-42D8-82EF-5420148DC9E1}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagMan.Data.Admin", "MagMan.Data.Admin\MagMan.Data.Admin.csproj", "{324914D5-2616-42D8-82EF-5420148DC9E1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
return;
|
||||
|
||||
reportProcess();
|
||||
await MagMan.Data.Admin.DbAdmin.migrateDbIdentity();
|
||||
await MagMan.Data.Admin.DbAdmin.MigrateDbIdentity();
|
||||
await ReloadData();
|
||||
reportChange();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace MagMan.UI.Health
|
||||
|
||||
public static async Task<HealthCheckResult> DbUserRoot(string dbName)
|
||||
{
|
||||
using (var adminDb = new DbAdminContext())
|
||||
using (var adminDb = new ServerAdminContext())
|
||||
{
|
||||
string description = "Try check MySql User table";
|
||||
List<MagMan.Data.Admin.DbModels.UserPriv> userList = new List<MagMan.Data.Admin.DbModels.UserPriv>();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@page "/AdminArea"
|
||||
|
||||
<PageTitle>Admin Area</PageTitle>
|
||||
|
||||
<h3>AdminArea</h3>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -40,6 +40,9 @@ string admConnStr = MagMan.Data.Admin.DbConfig.CONNECTION_STRING;
|
||||
// inizializzo il DB e creo (se necessario) l'utente
|
||||
MagMan.Data.Admin.DbConfig.CheckUser(nKey, sKey);
|
||||
MagMan.Data.Admin.DbConfig.ExecMigrationIdentity();
|
||||
// migrazione Db x gestione multitenant
|
||||
MagMan.Data.Admin.DbConfig.ExecMigrationMultiTenant();
|
||||
|
||||
|
||||
string connStringDB = MagMan.Data.Admin.DbConfig.CONNECTION_STRING;
|
||||
|
||||
@@ -87,8 +90,8 @@ builder.Services.Configure<DataProtectionTokenProviderOptions>(o =>
|
||||
|
||||
|
||||
|
||||
// setup MySql
|
||||
var serverVersion = MagMan.Data.Admin.DbConfig.MysqlServerVersion(admConnStr);
|
||||
// setup MySql
|
||||
var serverVersion = MagMan.Data.Admin.DbConfig.MysqlServerVersion(admConnStr);
|
||||
builder.Services.AddDbContext<IdentityContext>(options =>
|
||||
options.UseMySql(connStringDB, serverVersion));
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.main {
|
||||
main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -89,9 +89,7 @@
|
||||
}
|
||||
|
||||
.main > div {
|
||||
padding-left: 0.5rem !important;
|
||||
padding-right: 0.5rem !important;
|
||||
/*padding-left: 2rem !important;
|
||||
padding-right: 1.5rem !important;*/
|
||||
/*padding-left: 0.5rem !important;
|
||||
padding-right: 0.5rem !important;*/
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ flowchart TB
|
||||
|
||||
multiTenant--> tenantMgmt(Clienti)
|
||||
multiTenant--> MachMgmt(Macchine)
|
||||
multiTenant--> KeyMgmt(Chiavi)
|
||||
multiTenant--> KeyMgmt(Chiavi/Licenze)
|
||||
multiTenant--> UserMgmt(Utenti)
|
||||
|
||||
clientData --> MagData(Dati Magazzino)
|
||||
@@ -61,6 +61,8 @@ style clientData fill:#22AB19
|
||||
|
||||
In pratica le chiamate vengono inviate tutte al servizio web e da qui smistate per competenza e funzionalità verso i vari DB.
|
||||
|
||||
Chiavi/Licenze rappresentano le info associate ad ogni licenza software, che poi rappresenta una macchina tracciata.
|
||||
|
||||
A livello architetturale il progetto è separato tra la parte **Data.Admin** e **Data.Tenant**.
|
||||
|
||||
<div style="page-break-after: always; visibility: hidden"></div>
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user