Inizio costruzione EFCore layer
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
namespace WebDoorCreator.Core
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace WebDoorCreator.Core
|
||||
{
|
||||
public class Enum
|
||||
{
|
||||
public enum UserLevel
|
||||
{
|
||||
ND = 0,
|
||||
SuperAdmin = 1,
|
||||
Admin = 2,
|
||||
CompAdmin = 3,
|
||||
CompUser = 4,
|
||||
User = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.14" />
|
||||
<PackageReference Include="NLog" Version="5.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -6,7 +8,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WebDoorCreator.Data.Controllers
|
||||
{
|
||||
public class WebDoorCreatorController
|
||||
public class WebDoorCreatorController : IDisposable
|
||||
{
|
||||
private static IConfiguration _configuration;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public WebDoorCreatorController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
//Log.Info("Dispose di GWMSController");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
|
||||
// <Auto-Generated>
|
||||
// This is here so CodeMaid doesn't reorganize this document
|
||||
// </Auto-Generated>
|
||||
namespace WebDoorCreator.Data.DbModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Tabella dati Company
|
||||
/// </summary>
|
||||
[Table("Company")]
|
||||
public class CompanyModel
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int CompanyId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Codice esterno x riferimento (es ERP)
|
||||
/// </summary>
|
||||
[MaxLength(250)]
|
||||
public string CompanyExtCode { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Nome / ragione Sociale
|
||||
/// </summary>
|
||||
[MaxLength(500)]
|
||||
public string CompanyName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// indirizzo
|
||||
/// </summary>
|
||||
[MaxLength(250)]
|
||||
public string Address { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// CAP
|
||||
/// </summary>
|
||||
public int ZipCode { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Citta
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string City { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Stato
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string State { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// VAT / P.Iva
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string VAT { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Note private
|
||||
/// </summary>
|
||||
[MaxLength(500)]
|
||||
public string PrivateNote { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Codice GUID x collegare utente
|
||||
/// </summary>
|
||||
[MaxLength(150)]
|
||||
public string CompanyToken { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using WebDoorCreator.Data.DbModels;
|
||||
|
||||
namespace WebDoorCreator.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
|
||||
|
||||
//// 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 }
|
||||
// );
|
||||
|
||||
//// 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" }
|
||||
// );
|
||||
|
||||
//// 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" }
|
||||
// );
|
||||
|
||||
//// 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 }
|
||||
// );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebDoorCreator.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 = "SuperAdmin", NormalizedName = "SUPERADMIN" },
|
||||
new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" },
|
||||
new IdentityRole { Name = "CompAdmin", NormalizedName = "COMPADMIN" },
|
||||
new IdentityRole { Name = "CompUser", NormalizedName = "COMPUSER" },
|
||||
new IdentityRole { Name = "User", NormalizedName = "USER" }
|
||||
);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using static Org.BouncyCastle.Math.EC.ECCurve;
|
||||
|
||||
namespace WebDoorCreator.Data
|
||||
{
|
||||
public partial class WDCDataContext : DbContext
|
||||
{
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
public WDCDataContext()
|
||||
{
|
||||
}
|
||||
|
||||
public WDCDataContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public WDCDataContext(DbContextOptions<WDCDataContext> options) : base(options)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 02");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual DbSet<CompanyModel> DbSetCompany { get; set; }
|
||||
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("WDC.DB");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=WebDoorCreator;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UseCollation("Latin1_General_CI_AS");
|
||||
//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);
|
||||
}
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DbModels\" />
|
||||
<ProjectReference Include="..\WebDoorCreator.Core\WebDoorCreator.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"ConnectionStrings": {
|
||||
"Identity.DB": "Server=SQL2016DEV;Database=WebDoorCreator; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;",
|
||||
"Redis": "localhost:6379,DefaultDatabase=15,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false",
|
||||
"ApplicationDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=WebDoorCreator.UI;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
"WDC.DB": "Server=SQL2016DEV;Database=WebDoorCreator; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=WebDoorCreator.UI;"
|
||||
},
|
||||
"ExternalProviders": {
|
||||
"MailKit": {
|
||||
|
||||
Reference in New Issue
Block a user