86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using MagMan.Data.Admin.DbModels;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MagMan.Data.Admin
|
|
{
|
|
public class UserIdentityDbContext : IdentityDbContext
|
|
{
|
|
#region Public Constructors
|
|
|
|
public UserIdentityDbContext()
|
|
{
|
|
DbConfig.InitDb("localhost", "aaa", "bbb");
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{ }
|
|
}
|
|
|
|
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options) : base(options)
|
|
{
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{ }
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
public virtual DbSet<TableCount> DbSetCounts { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
string connString = DbConfig.CONNECTION_STRING;
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
var serverVersion = ServerVersion.AutoDetect(connString);
|
|
optionsBuilder.UseMySql(connString, serverVersion);
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
// nuova gestione in blocco come in GWMS e da https://stackoverflow.com/questions/34343599/how-to-seed-users-and-roles-with-code-first-migration-using-identity-asp-net-cor
|
|
|
|
builder.Seed();
|
|
base.OnModelCreating(builder);
|
|
|
|
|
|
// gestione come WDC:
|
|
#if false
|
|
|
|
// aggiunta ruoli
|
|
builder.ApplyConfiguration(new RoleConfiguration());
|
|
// aggiunta user admin base
|
|
builder.ApplyConfiguration(new UserAdminConfiguration());
|
|
// aggiunta ruoli utente
|
|
builder.ApplyConfiguration(new UserRoleConfiguration());
|
|
// Todo: aggiungere configurazione claims oltre ai roles...
|
|
#endif
|
|
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
}
|