Aggiunta proj MP.MONO.Data versione preliminare
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MP.MONO.Data.DbModels;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public partial class AdminContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public AdminContext()
|
||||
{
|
||||
}
|
||||
|
||||
public AdminContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public AdminContext(DbContextOptions<AdminContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// User management
|
||||
/// </summary>
|
||||
public DbSet<UserPriv> UserList { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connString = DbConfig.ADMIN_CONNECTION_STRING;
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
//connString = _configuration.GetConnectionString("GWMS.Data");
|
||||
//connString = "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;";
|
||||
var serverVersion = ServerVersion.AutoDetect(connString);
|
||||
optionsBuilder.UseMySql(connString, serverVersion);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UserPriv>().HasKey(c => new { c.Host, c.User });
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public class DbAdmin : IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public DbAdmin()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static bool checkCreateUser(string username, string pwd)
|
||||
{
|
||||
bool answ = false;
|
||||
using (AdminContext adbCtx = new AdminContext())
|
||||
{
|
||||
// ricerca utente...
|
||||
var numUser = adbCtx
|
||||
.UserList
|
||||
.Where(x => x.User == username)
|
||||
.ToList()
|
||||
.Count;
|
||||
if (numUser > 0)
|
||||
{
|
||||
answ = true;
|
||||
}
|
||||
if (!answ)
|
||||
{
|
||||
// creo utente
|
||||
string sqlCommand = "FLUSH PRIVILEGES;";
|
||||
adbCtx.Database.ExecuteSqlRaw(sqlCommand);
|
||||
sqlCommand = $"CREATE USER '{username}'@'localhost' IDENTIFIED BY '{pwd}';";
|
||||
adbCtx.Database.ExecuteSqlRaw(sqlCommand);
|
||||
sqlCommand = $"GRANT ALL ON *.* TO '{username}'@'localhost';";
|
||||
adbCtx.Database.ExecuteSqlRaw(sqlCommand);
|
||||
sqlCommand = "FLUSH PRIVILEGES;";
|
||||
adbCtx.Database.ExecuteSqlRaw(sqlCommand);
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task<bool> migrateDbIdentity()
|
||||
{
|
||||
bool answ = false;
|
||||
using (UserIdentityDbContext dbCtx = new UserIdentityDbContext())
|
||||
{
|
||||
await dbCtx.Database.MigrateAsync();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task<bool> migrateDbMain()
|
||||
{
|
||||
bool answ = false;
|
||||
#if false
|
||||
using (GWMSContext dbCtx = new GWMSContext())
|
||||
{
|
||||
await dbCtx.Database.MigrateAsync();
|
||||
answ = true;
|
||||
}
|
||||
#endif
|
||||
return answ;
|
||||
}
|
||||
|
||||
#if false
|
||||
public static bool resetPlantLogTable()
|
||||
{
|
||||
bool answ = false;
|
||||
using (GWMSContext dbCtx = new GWMSContext())
|
||||
{
|
||||
string sqlCommand = "TRUNCATE TABLE PlantLog;";
|
||||
dbCtx.Database.ExecuteSqlRaw(sqlCommand);
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public static class DbConfig
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
public static string DATABASE_NAME = "MAPO.MONO";
|
||||
|
||||
public static int DATABASE_PROCESS_TIMEOUT = 5;
|
||||
public static string DATABASE_PWD = "viadante16";
|
||||
|
||||
// Database config
|
||||
public static string DATABASE_SERV = "127.0.0.1";
|
||||
|
||||
public static string DATABASE_USER = "MAPO_MONO_User";
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// DB Connection string per azioni amministrative
|
||||
/// </summary>
|
||||
public static string ADMIN_CONNECTION_STRING { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// DB Connection string
|
||||
/// </summary>
|
||||
public static string CONNECTION_STRING { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static bool CheckUser(string nKey, string sKey)
|
||||
{
|
||||
// esecuzione script di install locale
|
||||
return DbAdmin.checkCreateUser(DATABASE_USER, DATABASE_PWD);
|
||||
}
|
||||
|
||||
public static bool ExecMigrationIdentity()
|
||||
{
|
||||
// esecuzione migrazione
|
||||
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbIdentity());
|
||||
migrateTask.Wait();
|
||||
return migrateTask.Result;
|
||||
}
|
||||
|
||||
public static bool ExecMigrationMain()
|
||||
{
|
||||
// esecuzione migrazione
|
||||
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbMain());
|
||||
migrateTask.Wait();
|
||||
return migrateTask.Result;
|
||||
}
|
||||
|
||||
public static void InitDb(string server, string nKey, string sKey)
|
||||
{
|
||||
DATABASE_SERV = server;
|
||||
DATABASE_NAME = $"GWMS_{nKey}";
|
||||
DATABASE_USER = $"user_{nKey}";
|
||||
DATABASE_PWD = $"pwd_{sKey}";
|
||||
CONNECTION_STRING = $"server={DATABASE_SERV};port=3306;database={DATABASE_NAME};uid={DATABASE_USER};pwd={DATABASE_PWD};sslmode=None";
|
||||
// stringa admin con utente root egalware...
|
||||
ADMIN_CONNECTION_STRING = $"server={DATABASE_SERV};port=3306;database=mysql;uid=root;pwd=Egalware_24068!;sslmode=None";
|
||||
}
|
||||
|
||||
public static ServerVersion MysqlServerVersion(string connString)
|
||||
{
|
||||
ServerVersion serverVersion = ServerVersion.AutoDetect(connString);
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace MP.MONO.Data.DbModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Classe fake x il conteggio tabelle e check preliminari
|
||||
/// </summary>
|
||||
[Keyless]
|
||||
public class TableCount
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public int Count { get; set; }
|
||||
public string TableName { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace MP.MONO.Data.DbModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Tabella dei USER di MySql
|
||||
/// </summary>
|
||||
[Table("user")]
|
||||
public class UserPriv
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
[Column("Host", Order = 1)]
|
||||
public string Host { get; set; } = "";
|
||||
|
||||
[Column("User", Order = 2)]
|
||||
public string User { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@@ -6,4 +6,31 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MP.MONO.Core\MP.MONO.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MailKit" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog" Version="4.7.13" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using MailKit.Net.Smtp;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MimeKit;
|
||||
using MimeKit.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementazione interfaccia email con pacchetto MailKIT
|
||||
///
|
||||
/// https://www.ryadel.com/en/asp-net-core-send-email-messages-smtp-mailkit/
|
||||
/// </summary>
|
||||
public class MailKitEmailSender : IEmailSender
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MailKitEmailSender(IOptions<MailKitEmailSenderOptions> options)
|
||||
{
|
||||
this.Options = options.Value;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public MailKitEmailSenderOptions Options { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public Task Execute(string to, string subject, string message)
|
||||
{
|
||||
// create message
|
||||
var email = new MimeMessage();
|
||||
email.Sender = MailboxAddress.Parse(Options.Sender_EMail);
|
||||
if (!string.IsNullOrEmpty(Options.Sender_Name))
|
||||
email.Sender.Name = Options.Sender_Name;
|
||||
email.From.Add(email.Sender);
|
||||
email.To.Add(MailboxAddress.Parse(to));
|
||||
email.Subject = subject;
|
||||
email.Body = new TextPart(TextFormat.Html) { Text = message };
|
||||
|
||||
// send email
|
||||
using (var smtp = new SmtpClient())
|
||||
{
|
||||
smtp.Connect(Options.Host_Address, Options.Host_Port, Options.Host_SecureSocketOptions);
|
||||
smtp.Authenticate(Options.Host_Username, Options.Host_Password);
|
||||
smtp.Send(email);
|
||||
smtp.Disconnect(true);
|
||||
}
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task SendEmailAsync(string email, string subject, string message)
|
||||
{
|
||||
return Execute(email, subject, message);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using MailKit.Security;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public class MailKitEmailSenderOptions
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public MailKitEmailSenderOptions()
|
||||
{
|
||||
Host_SecureSocketOptions = SecureSocketOptions.Auto;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public string Host_Address { get; set; }
|
||||
|
||||
public string Host_Password { get; set; }
|
||||
public int Host_Port { get; set; }
|
||||
|
||||
public SecureSocketOptions Host_SecureSocketOptions { get; set; }
|
||||
public string Host_Username { get; set; }
|
||||
public string Sender_EMail { get; set; }
|
||||
|
||||
public string Sender_Name { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using MP.MONO.Data.DbModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public partial class MapoMonoContext : DbContext
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public MapoMonoContext()
|
||||
{
|
||||
}
|
||||
|
||||
public MapoMonoContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public MapoMonoContext(DbContextOptions<MapoMonoContext> options) : base(options)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 02");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
#if false
|
||||
public virtual DbSet<RebootLogModel> DbRebootLog { get; set; }
|
||||
|
||||
public virtual DbSet<AlarmLogModel> DbSetAlarmLog { get; set; }
|
||||
|
||||
public virtual DbSet<ConfigModel> DbSetConfig { get; set; }
|
||||
|
||||
public virtual DbSet<ItemModel> DbSetItems { get; set; }
|
||||
|
||||
public virtual DbSet<AnKeyValModel> DbSetKeyVal { get; set; }
|
||||
|
||||
public virtual DbSet<ListValModel> DbSetListVal { get; set; }
|
||||
|
||||
public virtual DbSet<OrderModel> DbSetOrders { get; set; }
|
||||
|
||||
public virtual DbSet<ParamSendModel> DbSetParamSend { get; set; }
|
||||
|
||||
public virtual DbSet<ParamSetModel> DbSetParamSet { get; set; }
|
||||
|
||||
public virtual DbSet<PlantDetailModel> DbSetPlant { get; set; }
|
||||
|
||||
public virtual DbSet<PlantLogModel> DbSetPlantLog { get; set; }
|
||||
|
||||
public virtual DbSet<PlantStatusModel> DbSetPlantStatus { get; set; }
|
||||
|
||||
public virtual DbSet<WeekPlanModel> DbSetPlantSupplWeekPlan { get; set; }
|
||||
|
||||
public virtual DbSet<SupplierModel> DbSetSupplier { get; set; }
|
||||
|
||||
public virtual DbSet<TransporterModel> DbSetTransporter { get; set; }
|
||||
#endif
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
// default
|
||||
string connString = "Server=localhost;port=3306;database=MAPO.MONO;user=MapoUsr;pwd=M@poUsrS3cretPass!;sslmode=None;";
|
||||
|
||||
// tento setup da config
|
||||
try
|
||||
{
|
||||
// uso conn string calcolata
|
||||
connString = DbConfig.CONNECTION_STRING;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//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.Entity<PlantStatusModel>().HasKey(c => new { c.PlantId, c.FluxType });
|
||||
|
||||
//modelBuilder.Entity<ParamSendModel>().HasKey(c => new { c.PlantId, c.ParamUid });
|
||||
|
||||
modelBuilder.Seed();
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void DbForceMigrate()
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
Log.Info("DbForceMigrate: done!");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "DbForceMigrate: Exception during context initialization 01");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using MP.MONO.Data.DbModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public static class ModelBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Estensione per seed iniziale dei dati nel DB
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder"></param>
|
||||
public static void Seed(this ModelBuilder modelBuilder)
|
||||
{
|
||||
#if false
|
||||
// inizializzazione dei valori di default x USER
|
||||
modelBuilder.Entity<UserModel>().HasData(
|
||||
new UserModel { UserId = 1, AuthKey = "th1sIsTh3R1vrOfThNgt98", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "samuele.locatelli", Email = "samuele@steamware.net", Firstname = "Samuele", Lastname = "Locatelli" },
|
||||
new UserModel { UserId = 2, AuthKey = "th1sIsTh3R1vrOfThNgt91", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "giancarlo.rottoli", Email = "giancarlo@steamware.net", Firstname = "Giancarlo", Lastname = "Rottoli" },
|
||||
new UserModel { UserId = 3, AuthKey = "th1sIsTh3R1vrOfThNgt93", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "steamw.admin", Email = "info@steamware.net", Firstname = "Steamware", Lastname = "Admin" },
|
||||
new UserModel { UserId = 4, AuthKey = "th1sIsTh3R1vrOfThNgt97", Livello = UserLevel.Admin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "angelo.pizzaferri", Email = "a.pizzaferri@pizzaferripetroli.it", Firstname = "Angelo", Lastname = "Pizzaferri" },
|
||||
new UserModel { UserId = 5, AuthKey = "th1sIsTh3R1vrOfThNgt99", Livello = UserLevel.Admin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "andrei.valeanu", Email = "andrei.valeanu@winnlab.it", Firstname = "Andrei", Lastname = "Valeanu" },
|
||||
new UserModel { UserId = 6, AuthKey = "th1sIsTh3R1vrOfThNgt92", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 1, MaskTranspId = 0, UserName = "liquigas.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "LIQUIGAS" },
|
||||
new UserModel { UserId = 7, AuthKey = "th1sIsTh3R1vrOfThNgt94", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 2, MaskTranspId = 0, UserName = "vulkangas.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "VULKANGAS" },
|
||||
new UserModel { UserId = 8, AuthKey = "th1sIsTh3R1vrOfThNgt95", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 1, UserName = "levorato.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "LEVORATO" },
|
||||
new UserModel { UserId = 9, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 2, UserName = "traffik.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "TRAFFIK" },
|
||||
new UserModel { UserId = 10, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 1, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz03.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Collecchio" },
|
||||
new UserModel { UserId = 11, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 2, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz04.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Noceto" },
|
||||
new UserModel { UserId = 12, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 3, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz05.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Baganzola" },
|
||||
new UserModel { UserId = 13, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 4, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz08.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Pilastrello" }
|
||||
);
|
||||
#endif
|
||||
|
||||
#if false
|
||||
// inizializzazione dei valori di default x Plant
|
||||
modelBuilder.Entity<PlantDetailModel>().HasData(
|
||||
new PlantDetailModel { PlantId = 1, PlantCode = "PIZ03", PlantDesc = "Collecchio", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 },
|
||||
new PlantDetailModel { PlantId = 2, PlantCode = "PIZ04", PlantDesc = "Noceto", LevelMax = 28000, LevelReorder = 15000, OrderQtyStd = 18000 },
|
||||
new PlantDetailModel { PlantId = 3, PlantCode = "PIZ05", PlantDesc = "Baganzola", LevelMax = 24000, LevelReorder = 15000, OrderQtyStd = 18000 },
|
||||
new PlantDetailModel { PlantId = 4, PlantCode = "PIZ08", PlantDesc = "Pilastrello", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 },
|
||||
new PlantDetailModel { PlantId = 5, PlantCode = "PIZ09", PlantDesc = "Guardamiglio", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 }
|
||||
// new PlantDetailModel { PlantId = 1, PlantCode = "PIZ03", PlantDesc = "Collecchio", LevelMax = 26000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 },
|
||||
//new PlantDetailModel { PlantId = 2, PlantCode = "PIZ04", PlantDesc = "Noceto", LevelMax = 28000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 },
|
||||
//new PlantDetailModel { PlantId = 3, PlantCode = "PIZ05", PlantDesc = "Baganzola", LevelMax = 24000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 },
|
||||
//new PlantDetailModel { PlantId = 4, PlantCode = "PIZ08", PlantDesc = "Pilastrello", LevelMax = 26000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 }
|
||||
);
|
||||
#endif
|
||||
|
||||
#if false
|
||||
// inizializzazione dei valori di default x Fornitori
|
||||
modelBuilder.Entity<SupplierModel>().HasData(
|
||||
new SupplierModel { SupplierId = 1, SupplierCode = "LIQUIGAS", SupplierDesc = "Liquigas" },
|
||||
new SupplierModel { SupplierId = 2, SupplierCode = "VULKANGAS", SupplierDesc = "Vulkangas" }
|
||||
);
|
||||
#endif
|
||||
|
||||
#if false
|
||||
// inizializzazione dei valori di default x Trasportatori
|
||||
modelBuilder.Entity<TransporterModel>().HasData(
|
||||
new TransporterModel { TransporterId = 1, TransporterCode = "LEVO", TransporterDesc = "Levorato" },
|
||||
new TransporterModel { TransporterId = 2, TransporterCode = "TRAF", TransporterDesc = "Traffik" }
|
||||
);
|
||||
#endif
|
||||
|
||||
#if false
|
||||
// init consegne...
|
||||
modelBuilder.Entity<WeekPlanModel>().HasData(
|
||||
new WeekPlanModel { WeekPlanId = 1, DayNum = DayOfWeek.Monday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 2, DayNum = DayOfWeek.Tuesday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 3, DayNum = DayOfWeek.Wednesday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 2 },
|
||||
new WeekPlanModel { WeekPlanId = 4, DayNum = DayOfWeek.Thursday, DeliveryHour = 15, Note = "9K", PlantId = 2, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 5, DayNum = DayOfWeek.Thursday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 6, DayNum = DayOfWeek.Saturday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 7, DayNum = DayOfWeek.Tuesday, DeliveryHour = 14, Note = "3K", PlantId = 3, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 8, DayNum = DayOfWeek.Tuesday, DeliveryHour = 15, Note = "15K", PlantId = 4, SupplierId = 1, TransporterId = 1 },
|
||||
new WeekPlanModel { WeekPlanId = 9, DayNum = DayOfWeek.Tuesday, DeliveryHour = 17, Note = "18K", PlantId = 1, SupplierId = 2, TransporterId = 2 }
|
||||
);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public class RoleConfiguration : IEntityTypeConfiguration<IdentityRole>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public void Configure(EntityTypeBuilder<IdentityRole> builder)
|
||||
{
|
||||
builder.HasData(
|
||||
//new IdentityRole { Name = "Undef", NormalizedName = "UNDEF" },
|
||||
//new IdentityRole { Name = "ExtUser", NormalizedName = "EXTUSER" },
|
||||
//new IdentityRole { Name = "ExtTransp", NormalizedName = "EXTTRANSP" },
|
||||
new IdentityRole { Name = "User", NormalizedName = "USER" },
|
||||
new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" },
|
||||
new IdentityRole { Name = "SuperAdmin", NormalizedName = "SUPERADMIN" }
|
||||
);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.MONO.Data.DbModels;
|
||||
|
||||
namespace MP.MONO.Data
|
||||
{
|
||||
public class UserIdentityDbContext : IdentityDbContext
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserIdentityDbContext()
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{ }
|
||||
}
|
||||
|
||||
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
#if false
|
||||
// se non ci fosse... crea!
|
||||
Database.EnsureCreated();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{ }
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public 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);
|
||||
|
||||
builder.ApplyConfiguration(new RoleConfiguration());
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user