Dbcontext unico
This commit is contained in:
parent
efa0cb9106
commit
c5dfa2ef58
@ -2582,6 +2582,9 @@ namespace ApiPolo.Controllers
|
||||
case Clienti.Syscom:
|
||||
abilitata = true;
|
||||
break;
|
||||
case Clienti.Maras:
|
||||
abilitata = false;
|
||||
break;
|
||||
default:
|
||||
abilitata = false;
|
||||
break;
|
||||
@ -3127,6 +3130,9 @@ namespace ApiPolo.Controllers
|
||||
|
||||
/// <summary>Syscom</summary>
|
||||
public const string Sys = "S";
|
||||
|
||||
/// <summary>Maras</summary>
|
||||
public const string Mara = "M";
|
||||
}
|
||||
|
||||
/// <summary>trasforma un Saldiart in un Mag_New</summary>
|
||||
@ -3969,8 +3975,6 @@ namespace ApiPolo.Controllers
|
||||
{
|
||||
ten = tenAdhoc;
|
||||
}
|
||||
|
||||
|
||||
_magazzini = getMagazziniByTenant(ten);
|
||||
return await _magazzini.ToListAsync();
|
||||
}
|
||||
@ -5546,25 +5550,15 @@ namespace ApiPolo.Controllers
|
||||
}
|
||||
_chiamate = getChiamateByTenant(ten);
|
||||
|
||||
|
||||
|
||||
|
||||
var calltec = await _chiamate.Where(
|
||||
t => t.tccodice == tecnico
|
||||
&& t.chcodazi == ten
|
||||
).OrderByDescending(t => t.chdtapp).ToListAsync();
|
||||
|
||||
foreach (Chiamate ch in calltec)
|
||||
{
|
||||
{
|
||||
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);
|
||||
}
|
||||
// cerco le chiamate che devo fare per sostituzioni SE funzione abilitata
|
||||
@ -6619,7 +6613,7 @@ namespace ApiPolo.Controllers
|
||||
}*/
|
||||
try
|
||||
{
|
||||
_service.AddRappNewToDbAsync("AA",model);
|
||||
_service.AddRappNewToDbAsync("MARAS",model);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
@ -6649,29 +6643,29 @@ namespace ApiPolo.Controllers
|
||||
return StatusCode(StatusCodes.Status200OK, mex);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("chiamate/test2")]
|
||||
public async Task<ActionResult<Chiamate_out>> Test2([FromBody] Rapp_New model)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext("MARAS");
|
||||
//[HttpPost]
|
||||
//[Route("chiamate/test2")]
|
||||
//public async Task<ActionResult<Chiamate_out>> Test2([FromBody] Rapp_New model)
|
||||
//{
|
||||
// var dbContext = _dbContextFactory.GetDbContext("MARAS");
|
||||
|
||||
string mex = string.Empty;
|
||||
try
|
||||
{
|
||||
using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
||||
{
|
||||
await dbContext.Rapps.AddAsync(model);
|
||||
await dbContext.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mex = ex.Message;
|
||||
}
|
||||
// string mex = string.Empty;
|
||||
// try
|
||||
// {
|
||||
// using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
||||
// {
|
||||
// await dbContext.Rapps.AddAsync(model);
|
||||
// await dbContext.SaveChangesAsync();
|
||||
// await transaction.CommitAsync();
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// mex = ex.Message;
|
||||
// }
|
||||
|
||||
return StatusCode(StatusCodes.Status200OK, mex);
|
||||
}
|
||||
// return StatusCode(StatusCodes.Status200OK, mex);
|
||||
//}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,47 +1,74 @@
|
||||
using ApiPolo.Data;
|
||||
using ApiPolo.Interfaces;
|
||||
using ApiPolo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using static ApiPolo.Controllers.PoloController;
|
||||
|
||||
namespace ApiPolo
|
||||
{
|
||||
/// <summary></summary>
|
||||
public class Service
|
||||
{
|
||||
private readonly Maras_DbContext _dbContext;
|
||||
//private readonly Maras_DbContext _dbContext;
|
||||
private readonly ITenantDbContextFactory _dbContextFactory;
|
||||
|
||||
// Constructor injection of DbContext
|
||||
public Service(Maras_DbContext dbContext)
|
||||
/// <summary></summary>
|
||||
public Service( ITenantDbContextFactory dbContextFactory)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
//_dbContext = dbContext;
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Some logic to add entity to DbContext
|
||||
//await _dbContext.Rapps.AddAsync(model);
|
||||
//await _dbContext.SaveChangesAsync();
|
||||
if (tenant.Equals(Clienti.Maras))
|
||||
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
|
||||
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.SaveChangesAsync();
|
||||
transaction.Commit();
|
||||
await dbContext.Rapps.AddAsync(model);
|
||||
await dbContext.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
}
|
||||
//else if (dbContext is OtherDbContext otherDbContext)
|
||||
//{
|
||||
// await otherDbContext.AddAsync(entity);
|
||||
// await otherDbContext.SaveChangesAsync();
|
||||
//}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
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" });
|
||||
DateTime oggi = DateTime.Now;
|
||||
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");
|
||||
gen.IncludeXmlComments(filePath);
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
|
||||
//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=MARCO_PC\\SQL_2022;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",
|
||||
|
||||
/*"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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user