marco
This commit is contained in:
commit
ba97d8606e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,5 +2,6 @@
|
||||
"ExpandedNodes": [
|
||||
""
|
||||
],
|
||||
"SelectedNode": "\\ApiPolo.sln",
|
||||
"PreviewInSolutionExplorer": false
|
||||
}
|
||||
@ -53,7 +53,7 @@ using Microsoft.Extensions.Primitives;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
using ApiPolo.Models.Maras_DbContext;
|
||||
using ApiPolo.Data;
|
||||
|
||||
namespace ApiPolo.Controllers
|
||||
{
|
||||
@ -2999,6 +2999,9 @@ namespace ApiPolo.Controllers
|
||||
/// <summary>Syscom</summary>
|
||||
public const string Syscom = "A0001";
|
||||
|
||||
/// <summary>Syscom</summary>
|
||||
public const string Maras = "MARAS";
|
||||
|
||||
}
|
||||
/// <summary></summary>
|
||||
public static class suffClienti
|
||||
|
||||
137
ApiPolo/Controllers/TestController.cs
Normal file
137
ApiPolo/Controllers/TestController.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using ApiPolo.Interfaces;
|
||||
using ApiPolo.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiPolo.Controllers
|
||||
{
|
||||
public class TestController : Controller
|
||||
{
|
||||
//interfaccia con tutti i possibili dbset
|
||||
private readonly ITenantDbContextFactory _dbContextFactory;
|
||||
//DI con ITenantDbContextFactory
|
||||
public TestController(ITenantDbContextFactory dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
//ATTENZIONE - CONFLITTO TRA Compo_Impia_Table e
|
||||
|
||||
#region GET_BY_TENANT
|
||||
private DbSet<Tecnici> getTecniciByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Tecnici; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Rapp_New> getRappNewByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Rapps; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Chiamate> getChiamateByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Chiamate; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Chiusure>? getChiusureByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Chiusure;
|
||||
}
|
||||
private DbSet<Manprog> getManutenzioniByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Manutenzioni; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Prese> getPreseByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Prese; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Sto_Rapp> getSto_RappByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.StoRapp; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Anag> getClientiByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Clienti; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Caus_Rapp> getCausaliRappByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Causali; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Pagam> getPagamentiByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Pagamenti; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
|
||||
private DbSet<Saldiart> getSaldiartByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Saldi; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
/// <summary>
|
||||
/// CONFLITTO CON Compo_Impia_Table
|
||||
/// </summary>
|
||||
/*
|
||||
private DbSet<Compo_Impia_Table> getComponentiByTenant(string tenant)
|
||||
{ // IN CONFLITTO CON Compo_Impia_Table
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Componen; // Use Set<T>() to handle different DbContexts
|
||||
}*/
|
||||
private DbSet<Compo_Impia_Table> getComponentiTableByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Componen; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Magazzini> getMagazziniByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Magaz; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Mag_New> getMag_NewByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Mag; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Impianto> getImpiantiByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Impia; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Commessa> getCommesseByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Commesse; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Timbratura> getTimbratureByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Timbr; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
|
||||
private DbSet<Sto_Imp> getStoricoImpiantoByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.StoImp; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<AziendaRif> getAziendeRifByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Azi; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
private DbSet<Sostituzione> getSostituzioneByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Sost; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
171
ApiPolo/Data/Maras_DbContext.cs
Normal file
171
ApiPolo/Data/Maras_DbContext.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using ApiPolo.Interfaces;
|
||||
using ApiPolo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiPolo.Data
|
||||
{
|
||||
public class Maras_DbContext : DbContext,ITenantDbContext
|
||||
{
|
||||
#region PROPERTIES
|
||||
public DbSet<Caus_Rapp>? Causali { get; set; }
|
||||
|
||||
public DbSet<Chiusure>? Chiusure { get; set; }
|
||||
|
||||
public DbSet<AziendaRif>? Azi { get; set; }
|
||||
|
||||
public DbSet<CC_CI>? ccci { get; set; }
|
||||
|
||||
public DbSet<CC_CIWiev>? ccciWiev { get; set; }
|
||||
|
||||
public DbSet<Chiamate>? Chiamate { get; set; }
|
||||
|
||||
public DbSet<Anag>? Clienti { get; set; }
|
||||
|
||||
public DbSet<Compo_Impia_Table>? Componen { get; set; } // IN CONFLITTO CON Compo_Impia
|
||||
|
||||
//public DbSet<Compo_Impia>? Componen { get; set; } //CAMBIARE NOME!!!
|
||||
|
||||
public DbSet<Impianto>? Impia { get; set; }
|
||||
|
||||
public DbSet<Mag_New>? Mag { get; set; }
|
||||
|
||||
public DbSet<Magazzini>? Magaz { get; set; }
|
||||
|
||||
public DbSet<Manprog>? Manutenzioni { get; set; }
|
||||
|
||||
public DbSet<Pagam>? Pagamenti { get; set; }
|
||||
|
||||
public DbSet<Prese>? Prese { get; set; }
|
||||
|
||||
public DbSet<Rapp_New>? Rapps { get; set; }
|
||||
|
||||
public DbSet<Rappmast>? rapp { get; set; }
|
||||
|
||||
public DbSet<Sostituzione>? Sost { get; set; }
|
||||
|
||||
public DbSet<Saldiart>? Saldi { get; set; }
|
||||
|
||||
public DbSet<Sto_Rapp>? StoRapp { get; set; }
|
||||
|
||||
public DbSet<Tecnici>? Tecnici { get; set; }
|
||||
public DbSet<Sto_Imp>? StoImp { get; set; }
|
||||
|
||||
public DbSet<Timbratura>? Timbr { get; set; }
|
||||
|
||||
public DbSet<Commessa>? Commesse { get; set; }
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
void TryConfigureEntity(Action<ModelBuilder> configure, string entityName)
|
||||
{
|
||||
try
|
||||
{
|
||||
configure(modelBuilder);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Warning: Skipping entity '{entityName}' due to error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Caus_Rapp>().ToView("API_CAUS_RAPP"), "API_CAUS_RAPP");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Chiusure>().ToView("API_CHIUSURE"), "API_CHIUSURE");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<AziendaRif>().ToTable("PIAZIRIF");
|
||||
mb.Entity<AziendaRif>().HasKey(table => new
|
||||
{
|
||||
table.piazihoc,
|
||||
table.picodtec,
|
||||
table.pirifazi
|
||||
});
|
||||
}, "PIAZIRIF");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<CC_CI>().ToTable("PIASSCHIU");
|
||||
mb.Entity<CC_CI>().HasKey(table => new
|
||||
{
|
||||
table.picodazi,
|
||||
table.picodint,
|
||||
table.picodchi
|
||||
});
|
||||
}, "PIASSCHIU");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<CC_CIWiev>().ToView("API_ASSCHIU"), "API_ASSCHIU");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Chiamate>().ToView("API_CHIAMATE"), "API_CHIAMATE");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Anag>().ToView("API_CLIENTI"), "API_CLIENTI");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<Compo_Impia_Table>().ToTable("DISCOMICOMIMP");
|
||||
mb.Entity<Compo_Impia_Table>().HasKey(table => new
|
||||
{
|
||||
table.cocodimp,
|
||||
table.cprownum,
|
||||
table.cocodazi
|
||||
});
|
||||
}, "DISCOMICOMIMP");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Compo_Impia>().ToView("API_MICOMIMP"), "API_MICOMIMP");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Impianto>().ToView("API_IMPIANTI"), "API_IMPIANTI");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<Mag_New>().ToTable("DISCOMAG_NEW");
|
||||
mb.Entity<Mag_New>().HasKey(table => new
|
||||
{
|
||||
table.seriale_rapportino,
|
||||
table.riga
|
||||
});
|
||||
}, "DISCOMAG_NEW");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Magazzini>().ToTable("DISCOMAGAZZIN"), "DISCOMAGAZZIN");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Manprog>().ToView("API_MANPROG"), "API_MANPROG");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Pagam>().ToView("API_PAGAMENTI"), "API_PAGAMENTI");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<Prese>().ToTable("PIPRESA");
|
||||
mb.Entity<Prese>().HasKey(table => new
|
||||
{
|
||||
table.picodazi,
|
||||
table.pimpianto,
|
||||
table.picodint,
|
||||
table.pidatman
|
||||
});
|
||||
}, "PIPRESA");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Rapp_New>().ToTable("RAPP_NEW"), "RAPP_NEW");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Rappmast>().ToView("API_RAPPORTINI"), "API_RAPPORTINI");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Saldiart>().ToView("API_SALDIART_PREZZI"), "API_SALDIART_PREZZI");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Sostituzione>().ToView("API_SOSTITUZIONI"), "API_SOSTITUZIONI");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Sto_Rapp>().ToView("API_STO_RAPP"), "API_STO_RAPP");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Tecnici>().ToView("API_TECNICI"), "API_TECNICI");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Timbratura>().ToTable("TIMBRATURE"), "TIMBRATURE");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Commessa>().ToView("API_COMMESSE"), "API_COMMESSE");
|
||||
|
||||
TryConfigureEntity(mb => mb.Entity<Sto_Imp>().ToView("API_STO_IMP"), "API_STO_IMP");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
32
ApiPolo/Interfaces/ITenantDbContext.cs
Normal file
32
ApiPolo/Interfaces/ITenantDbContext.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ApiPolo.Models;
|
||||
|
||||
namespace ApiPolo.Interfaces
|
||||
{
|
||||
public interface ITenantDbContext
|
||||
{
|
||||
DbSet<Caus_Rapp>? Causali { get; set; }
|
||||
DbSet<Commessa>? Commesse { get; set; }
|
||||
DbSet<Chiusure>? Chiusure { get; set; }
|
||||
DbSet<AziendaRif>? Azi { get; set; }
|
||||
DbSet<CC_CI>? ccci { get; set; }
|
||||
DbSet<CC_CIWiev>? ccciWiev { get; set; }
|
||||
DbSet<Chiamate>? Chiamate { get; set; }
|
||||
DbSet<Anag>? Clienti { get; set; }
|
||||
DbSet<Compo_Impia_Table>? Componen { get; set; }
|
||||
DbSet<Impianto>? Impia { get; set; }
|
||||
DbSet<Mag_New>? Mag { get; set; }
|
||||
DbSet<Magazzini>? Magaz { get; set; }
|
||||
DbSet<Manprog>? Manutenzioni { get; set; }
|
||||
DbSet<Pagam>? Pagamenti { get; set; }
|
||||
DbSet<Prese>? Prese { get; set; }
|
||||
DbSet<Rapp_New>? Rapps { get; set; }
|
||||
DbSet<Rappmast>? rapp { get; set; }
|
||||
DbSet<Sostituzione>? Sost { get; set; }
|
||||
DbSet<Saldiart>? Saldi { get; set; }
|
||||
DbSet<Sto_Rapp>? StoRapp { get; set; }
|
||||
DbSet<Tecnici>? Tecnici { get; set; }
|
||||
DbSet<Timbratura>? Timbr { get; set; }
|
||||
DbSet<Sto_Imp>? StoImp { get; set; }
|
||||
}
|
||||
}
|
||||
9
ApiPolo/Interfaces/ITenantDbContextFactory.cs
Normal file
9
ApiPolo/Interfaces/ITenantDbContextFactory.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiPolo.Interfaces
|
||||
{
|
||||
public interface ITenantDbContextFactory
|
||||
{
|
||||
ITenantDbContext GetDbContext(string tenant);
|
||||
}
|
||||
}
|
||||
31
ApiPolo/Interfaces/TenantDbContextFactory.cs
Normal file
31
ApiPolo/Interfaces/TenantDbContextFactory.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ApiPolo.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static ApiPolo.Controllers.PoloController;
|
||||
using ApiPolo.Data;
|
||||
|
||||
namespace ApiPolo.Services
|
||||
{
|
||||
public class TenantDbContextFactory : ITenantDbContextFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public TenantDbContextFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public ITenantDbContext GetDbContext(string tenant)
|
||||
{
|
||||
return tenant switch
|
||||
{
|
||||
Clienti.Maras => _serviceProvider.GetRequiredService<Maras_DbContext>(),
|
||||
// Add other tenants as needed
|
||||
// Clienti.AnotherTenant => _serviceProvider.GetRequiredService<AnotherTenant_DbContext>(),
|
||||
_ => throw new KeyNotFoundException($"No DbContext found for tenant: {tenant}")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiPolo.Models.Maras_DbContext
|
||||
{
|
||||
public class Maras_DbContext : DbContext
|
||||
{
|
||||
public DbSet<Caus_Rapp>? Causali { get; set; }
|
||||
public DbSet<Chiusure>? Chiusure { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Caus_Rapp>().ToView("API_CAUS_RAPP");
|
||||
modelBuilder.Entity<Chiusure>().ToView("API_CHIUSURE");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,8 @@ using ApiPolo.Models.VT_dbcontext;
|
||||
using ApiPolo.Models.Tedesco_dbcontext;
|
||||
using ApiPolo.Models.Lift_web_dbcontext;
|
||||
using ApiPolo.Models.Security_dbcontext;
|
||||
using ApiPolo.Interfaces;
|
||||
using ApiPolo.Data;
|
||||
|
||||
namespace ApiPolo
|
||||
{
|
||||
@ -1013,6 +1015,13 @@ namespace ApiPolo
|
||||
));
|
||||
#endregion
|
||||
|
||||
services.AddDbContext<Maras_DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MARAS")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
|
||||
// FACTORY MUTI-TENANT
|
||||
services.AddSingleton<ITenantDbContextFactory, TenantDbContextFactory>();
|
||||
|
||||
|
||||
services.AddSwaggerGen(gen =>
|
||||
{
|
||||
|
||||
@ -55,7 +55,9 @@
|
||||
/*"SYSCOM": "Data Source=docker1.polo;Initial Catalog= AHRW_SYSCOM;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",*/
|
||||
"SYSCOM": "Data Source=dbsql01.poloinformatico.it;Initial Catalog= AHRW_SYSCOM;User Id=syscom; Password=4@QLHV?cpVYbr+GB;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||
|
||||
"TEDESCO": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog= AHR_TEDESCO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
|
||||
"TEDESCO": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog= AHR_TEDESCO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||
|
||||
"MARAS": "Data Source=docker1.polo;Initial Catalog= AHRW_MARAS;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False"
|
||||
},
|
||||
"JWT": {
|
||||
"ValidAudience": "http://localhost:4200",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user