Dbcontext unico
This commit is contained in:
parent
efa0cb9106
commit
c5dfa2ef58
@ -2582,6 +2582,9 @@ namespace ApiPolo.Controllers
|
|||||||
case Clienti.Syscom:
|
case Clienti.Syscom:
|
||||||
abilitata = true;
|
abilitata = true;
|
||||||
break;
|
break;
|
||||||
|
case Clienti.Maras:
|
||||||
|
abilitata = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
abilitata = false;
|
abilitata = false;
|
||||||
break;
|
break;
|
||||||
@ -3127,6 +3130,9 @@ namespace ApiPolo.Controllers
|
|||||||
|
|
||||||
/// <summary>Syscom</summary>
|
/// <summary>Syscom</summary>
|
||||||
public const string Sys = "S";
|
public const string Sys = "S";
|
||||||
|
|
||||||
|
/// <summary>Maras</summary>
|
||||||
|
public const string Mara = "M";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>trasforma un Saldiart in un Mag_New</summary>
|
/// <summary>trasforma un Saldiart in un Mag_New</summary>
|
||||||
@ -3969,8 +3975,6 @@ namespace ApiPolo.Controllers
|
|||||||
{
|
{
|
||||||
ten = tenAdhoc;
|
ten = tenAdhoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_magazzini = getMagazziniByTenant(ten);
|
_magazzini = getMagazziniByTenant(ten);
|
||||||
return await _magazzini.ToListAsync();
|
return await _magazzini.ToListAsync();
|
||||||
}
|
}
|
||||||
@ -5546,9 +5550,6 @@ namespace ApiPolo.Controllers
|
|||||||
}
|
}
|
||||||
_chiamate = getChiamateByTenant(ten);
|
_chiamate = getChiamateByTenant(ten);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var calltec = await _chiamate.Where(
|
var calltec = await _chiamate.Where(
|
||||||
t => t.tccodice == tecnico
|
t => t.tccodice == tecnico
|
||||||
&& t.chcodazi == ten
|
&& t.chcodazi == ten
|
||||||
@ -5557,14 +5558,7 @@ namespace ApiPolo.Controllers
|
|||||||
foreach (Chiamate ch in calltec)
|
foreach (Chiamate ch in calltec)
|
||||||
{
|
{
|
||||||
Chiamate_out o = new Chiamate_out();
|
Chiamate_out o = new Chiamate_out();
|
||||||
if (tenOut.Equals(Clienti.VT))
|
|
||||||
{
|
|
||||||
o = fillChiamateOutVT(ch, ten);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
o = fillChiamateOut(ch, ten);
|
o = fillChiamateOut(ch, ten);
|
||||||
}
|
|
||||||
ilist.Add(o);
|
ilist.Add(o);
|
||||||
}
|
}
|
||||||
// cerco le chiamate che devo fare per sostituzioni SE funzione abilitata
|
// cerco le chiamate che devo fare per sostituzioni SE funzione abilitata
|
||||||
@ -6619,7 +6613,7 @@ namespace ApiPolo.Controllers
|
|||||||
}*/
|
}*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_service.AddRappNewToDbAsync("AA",model);
|
_service.AddRappNewToDbAsync("MARAS",model);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
@ -6649,29 +6643,29 @@ namespace ApiPolo.Controllers
|
|||||||
return StatusCode(StatusCodes.Status200OK, mex);
|
return StatusCode(StatusCodes.Status200OK, mex);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
//[HttpPost]
|
||||||
[Route("chiamate/test2")]
|
//[Route("chiamate/test2")]
|
||||||
public async Task<ActionResult<Chiamate_out>> Test2([FromBody] Rapp_New model)
|
//public async Task<ActionResult<Chiamate_out>> Test2([FromBody] Rapp_New model)
|
||||||
{
|
//{
|
||||||
var dbContext = _dbContextFactory.GetDbContext("MARAS");
|
// var dbContext = _dbContextFactory.GetDbContext("MARAS");
|
||||||
|
|
||||||
string mex = string.Empty;
|
// string mex = string.Empty;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
// using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
||||||
{
|
// {
|
||||||
await dbContext.Rapps.AddAsync(model);
|
// await dbContext.Rapps.AddAsync(model);
|
||||||
await dbContext.SaveChangesAsync();
|
// await dbContext.SaveChangesAsync();
|
||||||
await transaction.CommitAsync();
|
// await transaction.CommitAsync();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
mex = ex.Message;
|
// mex = ex.Message;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return StatusCode(StatusCodes.Status200OK, mex);
|
// return StatusCode(StatusCodes.Status200OK, mex);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,47 +1,74 @@
|
|||||||
using ApiPolo.Data;
|
using ApiPolo.Data;
|
||||||
|
using ApiPolo.Interfaces;
|
||||||
using ApiPolo.Models;
|
using ApiPolo.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
using static ApiPolo.Controllers.PoloController;
|
using static ApiPolo.Controllers.PoloController;
|
||||||
|
|
||||||
namespace ApiPolo
|
namespace ApiPolo
|
||||||
{
|
{
|
||||||
|
/// <summary></summary>
|
||||||
public class Service
|
public class Service
|
||||||
{
|
{
|
||||||
private readonly Maras_DbContext _dbContext;
|
//private readonly Maras_DbContext _dbContext;
|
||||||
|
private readonly ITenantDbContextFactory _dbContextFactory;
|
||||||
|
|
||||||
// Constructor injection of DbContext
|
// Constructor injection of DbContext
|
||||||
public Service(Maras_DbContext dbContext)
|
/// <summary></summary>
|
||||||
|
public Service( ITenantDbContextFactory dbContextFactory)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
//_dbContext = dbContext;
|
||||||
|
_dbContextFactory = dbContextFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example method
|
// Example method
|
||||||
|
/// <summary></summary>
|
||||||
|
//public async Task AddRappNewToDbAsync2(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.");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
/// <summary></summary>
|
||||||
public async Task AddRappNewToDbAsync(string tenant, Rapp_New model)
|
public async Task AddRappNewToDbAsync(string tenant, Rapp_New model)
|
||||||
{
|
{
|
||||||
// Some logic to add entity to DbContext
|
|
||||||
//await _dbContext.Rapps.AddAsync(model);
|
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||||
//await _dbContext.SaveChangesAsync();
|
|
||||||
if (tenant.Equals(Clienti.Maras))
|
string mex = string.Empty;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using (var transaction = _dbContext.Database.BeginTransaction())
|
using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
||||||
{
|
{
|
||||||
await _dbContext.Rapps.AddAsync(model);
|
await dbContext.Rapps.AddAsync(model);
|
||||||
await _dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
transaction.Commit();
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else if (dbContext is OtherDbContext otherDbContext)
|
catch (Exception ex)
|
||||||
//{
|
|
||||||
// await otherDbContext.AddAsync(entity);
|
|
||||||
// await otherDbContext.SaveChangesAsync();
|
|
||||||
//}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Unsupported DbContext type.");
|
mex = ex.Message;
|
||||||
|
throw new InvalidOperationException("Error in Service: "+mex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1022,7 +1022,7 @@ namespace ApiPolo
|
|||||||
//gen.SwaggerDoc("v1", new OpenApiInfo { Title = "POLO API WS2016", Version = "v3.3" });
|
//gen.SwaggerDoc("v1", new OpenApiInfo { Title = "POLO API WS2016", Version = "v3.3" });
|
||||||
DateTime oggi = DateTime.Now;
|
DateTime oggi = DateTime.Now;
|
||||||
string dt = oggi.ToString();
|
string dt = oggi.ToString();
|
||||||
gen.SwaggerDoc("v1", new OpenApiInfo { Title = "POLO API - v.app 1.30", Version = dt });
|
gen.SwaggerDoc("v1", new OpenApiInfo { Title = "POLO API V2 - v.app 1.30", Version = dt });
|
||||||
|
|
||||||
var filePath = Path.Combine(System.AppContext.BaseDirectory, "ApiPolo.xml");
|
var filePath = Path.Combine(System.AppContext.BaseDirectory, "ApiPolo.xml");
|
||||||
gen.IncludeXmlComments(filePath);
|
gen.IncludeXmlComments(filePath);
|
||||||
|
|||||||
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
//connessione non sicura: Encrypt=False
|
//connessione non sicura: Encrypt=False
|
||||||
|
|
||||||
//"ApiStr": "Data Source=172.25.30.1;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
"ApiStr": "Data Source=172.25.30.1;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||||
"ApiStr": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
//"ApiStr": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||||
|
|
||||||
/*"FERRA": "Data Source=10.0.0.10;Initial Catalog=AHR60_FERRARI;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",*/
|
/*"FERRA": "Data Source=10.0.0.10;Initial Catalog=AHR60_FERRARI;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",*/
|
||||||
"FERRA": "Data Source=37.159.179.14;Initial Catalog=AHR80_TEST;User Id=AppPolo; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;Trust Server Certificate=True",
|
"FERRA": "Data Source=37.159.179.14;Initial Catalog=AHR80_TEST;User Id=AppPolo; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;Trust Server Certificate=True",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user