prima bozza service
This commit is contained in:
parent
c8489d34dd
commit
48c195e477
@ -40,6 +40,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using ApiPolo.Data;
|
using ApiPolo.Data;
|
||||||
using ApiPolo.Interfaces;
|
using ApiPolo.Interfaces;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
|
|
||||||
namespace ApiPolo.Controllers
|
namespace ApiPolo.Controllers
|
||||||
{
|
{
|
||||||
@ -54,6 +55,7 @@ namespace ApiPolo.Controllers
|
|||||||
private readonly ConfigurazioniDbContext? _config;
|
private readonly ConfigurazioniDbContext? _config;
|
||||||
private readonly IConfiguration? _configuration;
|
private readonly IConfiguration? _configuration;
|
||||||
private readonly ITenantDbContextFactory _dbContextFactory;
|
private readonly ITenantDbContextFactory _dbContextFactory;
|
||||||
|
private readonly Service _service;
|
||||||
|
|
||||||
private readonly TokenDbContext? _tokens;
|
private readonly TokenDbContext? _tokens;
|
||||||
private readonly Maras_DbContext _Maras;
|
private readonly Maras_DbContext _Maras;
|
||||||
@ -529,6 +531,7 @@ namespace ApiPolo.Controllers
|
|||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
ConfigurazioniDbContext config,
|
ConfigurazioniDbContext config,
|
||||||
ITenantDbContextFactory dbContextFactory,
|
ITenantDbContextFactory dbContextFactory,
|
||||||
|
Service service,
|
||||||
TokenDbContext tokens,
|
TokenDbContext tokens,
|
||||||
Maras_DbContext maras
|
Maras_DbContext maras
|
||||||
/*
|
/*
|
||||||
@ -899,6 +902,7 @@ namespace ApiPolo.Controllers
|
|||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
_service = service;
|
||||||
_config = config;
|
_config = config;
|
||||||
_tokens = tokens;
|
_tokens = tokens;
|
||||||
_Maras = maras;
|
_Maras = maras;
|
||||||
@ -1326,11 +1330,11 @@ namespace ApiPolo.Controllers
|
|||||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||||
return dbContext.Prog; // Use Set<T>() to handle different DbContexts
|
return dbContext.Prog; // Use Set<T>() to handle different DbContexts
|
||||||
}
|
}
|
||||||
private DbSet<Prog> getChiamateProgressiviByTenant(string tenant)
|
//private DbSet<Prog> getChiamateProgressiviByTenant(string tenant)
|
||||||
{
|
//{
|
||||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
// var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||||
return dbContext.Progressivi; // Use Set<T>() to handle different DbContexts
|
// return dbContext.Progressivi; // Use Set<T>() to handle different DbContexts
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CONFLITTO CON Compo_Impia_Table
|
/// CONFLITTO CON Compo_Impia_Table
|
||||||
@ -1387,11 +1391,11 @@ namespace ApiPolo.Controllers
|
|||||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||||
return dbContext.Sost; // Use Set<T>() to handle different DbContexts
|
return dbContext.Sost; // Use Set<T>() to handle different DbContexts
|
||||||
}
|
}
|
||||||
private DbSet<Compo_Impia> getComponentiByTenant(string tenant)
|
//private DbSet<Compo_Impia> getComponentiByTenant(string tenant)
|
||||||
{
|
//{
|
||||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
// var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||||
return dbContext.Compo; // Use Set<T>() to handle different DbContexts
|
// return dbContext.Compo; // Use Set<T>() to handle different DbContexts
|
||||||
}
|
//}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Utility
|
#region Utility
|
||||||
@ -5647,15 +5651,15 @@ namespace ApiPolo.Controllers
|
|||||||
newSerial = await getSeriale(token);
|
newSerial = await getSeriale(token);
|
||||||
Rapp_New r = await fillRappNewByInput(model, token, newSerial, _confLette);
|
Rapp_New r = await fillRappNewByInput(model, token, newSerial, _confLette);
|
||||||
|
|
||||||
Maras_DbContext dbContext = (Maras_DbContext)_dbContextFactory.GetDbContext("MARAS");
|
//Maras_DbContext dbContext = (Maras_DbContext)_dbContextFactory.GetDbContext("MARAS");
|
||||||
|
|
||||||
|
|
||||||
using (var transaction = dbContext.Database.BeginTransaction())
|
//using (var transaction = dbContext.Database.BeginTransaction())
|
||||||
{
|
//{
|
||||||
await dbContext.Rapps.AddAsync(r);
|
// await dbContext.Rapps.AddAsync(r);
|
||||||
await dbContext.SaveChangesAsync();
|
// await dbContext.SaveChangesAsync();
|
||||||
transaction.Commit();
|
// transaction.Commit();
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//scrittura test
|
//scrittura test
|
||||||
@ -6593,8 +6597,40 @@ namespace ApiPolo.Controllers
|
|||||||
[Route("chiamate/test")]
|
[Route("chiamate/test")]
|
||||||
public async Task<ActionResult<Chiamate_out>> test([FromBody] Rapp_New model)
|
public async Task<ActionResult<Chiamate_out>> test([FromBody] Rapp_New model)
|
||||||
{
|
{
|
||||||
Maras_DbContext dbContext = (Maras_DbContext)_dbContextFactory.GetDbContext("MARAS");
|
|
||||||
string mex = string.Empty;
|
string mex = string.Empty;
|
||||||
|
/*
|
||||||
|
using (var dbContext = _dbContextFactory.CreateDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Add the entity to the DbSet
|
||||||
|
await dbContext.Set<T>().AddAsync(entity);
|
||||||
|
|
||||||
|
// Save the changes to the database
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Handle exceptions as necessary
|
||||||
|
Console.WriteLine($"Error inserting entity: {ex.Message}");
|
||||||
|
// Optionally rethrow or log the errorMaras
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_service.AddRappNewToDbAsync("AA",model);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
mex = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Maras_DbContext dbContext = (Maras_DbContext)_dbContextFactory.GetDbContext("MARAS");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var transaction = dbContext.Database.BeginTransaction())
|
using (var transaction = dbContext.Database.BeginTransaction())
|
||||||
@ -6604,10 +6640,11 @@ namespace ApiPolo.Controllers
|
|||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
mex = ex.Message;
|
mex = ex.Message;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return StatusCode(StatusCodes.Status200OK, mex);
|
return StatusCode(StatusCodes.Status200OK, mex);
|
||||||
}
|
}
|
||||||
@ -8450,28 +8487,17 @@ namespace ApiPolo.Controllers
|
|||||||
string ten = getClaimValueByToken(token, "tenant");
|
string ten = getClaimValueByToken(token, "tenant");
|
||||||
List<Compo_Impia> lst = new List<Compo_Impia>();
|
List<Compo_Impia> lst = new List<Compo_Impia>();
|
||||||
|
|
||||||
if(!ten.Equals(Clienti.VT))
|
Compo_Impia ci = new Compo_Impia();
|
||||||
{
|
ci.cocodimp = codimp;
|
||||||
_compo = getComponentiByTenant(ten);
|
ci.cprownum = 1;
|
||||||
|
ci.cocodart = "00001";
|
||||||
var co = await _compo.Where(
|
ci.cocodazi = "AZI02";
|
||||||
t => t.cocodimp == codimp
|
ci.ardesart = "Tubo in metallo";
|
||||||
).ToListAsync();
|
|
||||||
lst = co;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Compo_Impia ci = new Compo_Impia();
|
|
||||||
ci.cocodimp = codimp;
|
|
||||||
ci.cprownum = 1;
|
|
||||||
ci.cocodart = "00001";
|
|
||||||
ci.cocodazi = "AZI02";
|
|
||||||
ci.ardesart = "Tubo in metallo";
|
|
||||||
|
|
||||||
|
|
||||||
lst.Add(ci);
|
lst.Add(ci);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
return StatusCode(StatusCodes.Status200OK, lst);
|
return StatusCode(StatusCodes.Status200OK, lst);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -13486,15 +13512,17 @@ namespace ApiPolo.Controllers
|
|||||||
private async Task<Prog> leggiCpwarnSeriale(string tenant, string tablecode)
|
private async Task<Prog> leggiCpwarnSeriale(string tenant, string tablecode)
|
||||||
{
|
{
|
||||||
//autorun float
|
//autorun float
|
||||||
_chiamateprogr = getChiamateProgressiviByTenant(tenant);
|
//_chiamateprogr = getChiamateProgressiviByTenant(tenant);
|
||||||
var cpwarn = await _chiamateprogr.Where(p => p.tablecode != null && p.tablecode.Contains(tablecode) && p.tablecode.Contains(tenant)).FirstAsync();
|
//var cpwarn = await _chiamateprogr.Where(p => p.tablecode != null && p.tablecode.Contains(tablecode) && p.tablecode.Contains(tenant)).FirstAsync();
|
||||||
|
Prog cpwarn = new Prog();
|
||||||
return cpwarn;
|
return cpwarn;
|
||||||
}
|
}
|
||||||
private async Task<Prog> leggiCpwarnProg(string tenant, string tablecode, string codiceEsercizio)
|
private async Task<Prog> leggiCpwarnProg(string tenant, string tablecode, string codiceEsercizio)
|
||||||
{
|
{
|
||||||
//autorun float
|
//autorun float
|
||||||
_chiamateprogr = getChiamateProgressiviByTenant(tenant);
|
//_chiamateprogr = getChiamateProgressiviByTenant(tenant);
|
||||||
var cpwarn = await _chiamateprogr.Where(p => p.tablecode != null && p.tablecode.Contains(tablecode) && p.tablecode.Contains(codiceEsercizio) && p.tablecode.Contains(tenant)).FirstAsync();
|
//var cpwarn = await _chiamateprogr.Where(p => p.tablecode != null && p.tablecode.Contains(tablecode) && p.tablecode.Contains(codiceEsercizio) && p.tablecode.Contains(tenant)).FirstAsync();
|
||||||
|
Prog cpwarn = new Prog();
|
||||||
return cpwarn;
|
return cpwarn;
|
||||||
}
|
}
|
||||||
private async Task<Prog2> leggiCpwarnProgDecimal(string tenant, string tablecode, string codiceEsercizio)
|
private async Task<Prog2> leggiCpwarnProgDecimal(string tenant, string tablecode, string codiceEsercizio)
|
||||||
|
|||||||
@ -57,13 +57,17 @@ namespace ApiPolo.Data
|
|||||||
public DbSet<Commessa>? Commesse { get; set; }
|
public DbSet<Commessa>? Commesse { get; set; }
|
||||||
|
|
||||||
public DbSet<Prog2>? Prog { get; set; }
|
public DbSet<Prog2>? Prog { get; set; }
|
||||||
public DbSet<Prog>? Progressivi { get; set; }
|
//public DbSet<Prog>? Progressivi { get; set; }
|
||||||
public DbSet<Compo_Impia>? Compo { get; set; }
|
//public DbSet<Compo_Impia>? Compo { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private readonly DbContextOptions<Maras_DbContext> _options;
|
||||||
/// <summary></summary>
|
/// <summary></summary>
|
||||||
public Maras_DbContext(DbContextOptions<Maras_DbContext> options) : base(options)
|
public Maras_DbContext(DbContextOptions<Maras_DbContext> options) : base(options)
|
||||||
{
|
{
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary></summary>
|
/// <summary></summary>
|
||||||
@ -174,7 +178,17 @@ namespace ApiPolo.Data
|
|||||||
|
|
||||||
TryConfigureEntity(mb => mb.Entity<Sto_Imp>().ToView("API_STO_IMP"), "API_STO_IMP");
|
TryConfigureEntity(mb => mb.Entity<Sto_Imp>().ToView("API_STO_IMP"), "API_STO_IMP");
|
||||||
|
|
||||||
|
TryConfigureEntity(mb =>
|
||||||
|
{
|
||||||
|
mb.Entity<Prog2>().ToTable("CPWARN");
|
||||||
|
mb.Entity<Prog2>().HasKey(table => new
|
||||||
|
{
|
||||||
|
table.tablecode,
|
||||||
|
table.warncode
|
||||||
|
});
|
||||||
|
}, "CPWARN");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,8 @@ namespace ApiPolo.Interfaces
|
|||||||
DbSet<Sto_Imp>? StoImp { get; set; }
|
DbSet<Sto_Imp>? StoImp { get; set; }
|
||||||
|
|
||||||
DbSet<Prog2>? Prog { get; set; }
|
DbSet<Prog2>? Prog { get; set; }
|
||||||
DbSet<Prog>? Progressivi { get; set; }
|
//DbSet<Prog>? Progressivi { get; set; }
|
||||||
DbSet<Compo_Impia>? Compo { get; set; }
|
//DbSet<Compo_Impia>? Compo { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
ApiPolo/Service.cs
Normal file
47
ApiPolo/Service.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using ApiPolo.Data;
|
||||||
|
using ApiPolo.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static ApiPolo.Controllers.PoloController;
|
||||||
|
|
||||||
|
namespace ApiPolo
|
||||||
|
{
|
||||||
|
public class Service
|
||||||
|
{
|
||||||
|
private readonly Maras_DbContext _dbContext;
|
||||||
|
|
||||||
|
// Constructor injection of DbContext
|
||||||
|
public Service(Maras_DbContext dbContext)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example method
|
||||||
|
public async Task AddRappNewToDbAsync(string tenant, Rapp_New model)
|
||||||
|
{
|
||||||
|
// Some logic to add entity to DbContext
|
||||||
|
//await _dbContext.Rapps.AddAsync(model);
|
||||||
|
//await _dbContext.SaveChangesAsync();
|
||||||
|
if (tenant.Equals(Clienti.Maras))
|
||||||
|
{
|
||||||
|
using (var transaction = _dbContext.Database.BeginTransaction())
|
||||||
|
{
|
||||||
|
await _dbContext.Rapps.AddAsync(model);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else if (dbContext is OtherDbContext otherDbContext)
|
||||||
|
//{
|
||||||
|
// await otherDbContext.AddAsync(entity);
|
||||||
|
// await otherDbContext.SaveChangesAsync();
|
||||||
|
//}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unsupported DbContext type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ using Microsoft.OpenApi.Models;
|
|||||||
using ApiPolo.Services;
|
using ApiPolo.Services;
|
||||||
using ApiPolo.Interfaces;
|
using ApiPolo.Interfaces;
|
||||||
using ApiPolo.Data;
|
using ApiPolo.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
|
|
||||||
namespace ApiPolo
|
namespace ApiPolo
|
||||||
{
|
{
|
||||||
@ -1011,6 +1012,7 @@ namespace ApiPolo
|
|||||||
|
|
||||||
// FACTORY MUTI-TENANT
|
// FACTORY MUTI-TENANT
|
||||||
services.AddScoped<ITenantDbContextFactory, TenantDbContextFactory>();
|
services.AddScoped<ITenantDbContextFactory, TenantDbContextFactory>();
|
||||||
|
services.AddScoped<Service>();
|
||||||
|
|
||||||
|
|
||||||
services.AddSwaggerGen(gen =>
|
services.AddSwaggerGen(gen =>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user