75 lines
2.0 KiB
C#
75 lines
2.0 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);
|
|
|
|
// aggiunta ruoli
|
|
builder.ApplyConfiguration(new UserRoleConfiguration());
|
|
// aggiunta user admin base
|
|
builder.ApplyConfiguration(new UserAdminConfiguration());
|
|
|
|
// Todo: aggiungere configurazione claims oltre ai roles...
|
|
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
}
|