gestione immagini buono
This commit is contained in:
parent
ad5122b1ca
commit
a5eee0b6cf
@ -1384,7 +1384,11 @@ namespace ApiPolo.Controllers
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.ChiamateTables; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
|
||||
private DbSet<BuoniLW> getBuoniByTenant(string tenant)
|
||||
{
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
return dbContext.Buoni; // Use Set<T>() to handle different DbContexts
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Utility
|
||||
@ -7334,92 +7338,30 @@ namespace ApiPolo.Controllers
|
||||
{
|
||||
ten = tenConf;
|
||||
}
|
||||
string fileName = string.Empty;
|
||||
|
||||
Console.WriteLine(string.Format("*********** {2} INIZIO Chiamata al metodo upload: tenant:{0} tenant2: {3} tenantConf: {4} file: {1} tecnico:{5}", ten, nomefile, DateTime.Now.ToString(),ten2,tenConf, tecnico));
|
||||
_confLette = await readConf(tenConf);
|
||||
|
||||
|
||||
//string fileName = string.Empty;
|
||||
//_confLette = await readConf(tenConf);
|
||||
|
||||
try
|
||||
{
|
||||
long size = files.Length;
|
||||
if(string.IsNullOrEmpty(nomefile))
|
||||
|
||||
BuoniLW modelsys = new BuoniLW();
|
||||
modelsys.azienda = ten;
|
||||
if (nomefile.Length > 8)
|
||||
nomefile = nomefile.Substring(0, 8);
|
||||
modelsys.ser_buono = nomefile;
|
||||
modelsys.dt_ins = DateTime.Now;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
fileName = Path.GetFileName(files.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = nomefile;
|
||||
files.CopyTo(ms);
|
||||
byte[] byteArray = ms.GetBuffer();
|
||||
string base64String = Convert.ToBase64String(byteArray);
|
||||
modelsys.immagine = base64String;
|
||||
}
|
||||
//scrittura
|
||||
await _service.AddBuonoToDbAsync(ten,modelsys);
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
|
||||
string url = string.Empty;
|
||||
string usr = string.Empty;
|
||||
string pwd = string.Empty;
|
||||
string ip = string.Empty;
|
||||
int? port = 0;
|
||||
|
||||
switch (ten)
|
||||
{
|
||||
case Clienti.LW:
|
||||
|
||||
#region inserimento tabella
|
||||
BuoniLW model2 = new BuoniLW();
|
||||
model2.azienda = ten;
|
||||
if (nomefile.Length > 8)
|
||||
nomefile = nomefile.Substring(0, 8);
|
||||
model2.ser_buono = nomefile;
|
||||
model2.dt_ins = DateTime.Now;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
files.CopyTo(ms);
|
||||
byte[] byteArray = ms.GetBuffer();
|
||||
string base64String = Convert.ToBase64String(byteArray);
|
||||
model2.immagine = base64String;
|
||||
}
|
||||
|
||||
/*
|
||||
using (var transaction = _LW_Buoni.Database.BeginTransaction())
|
||||
{
|
||||
await _LW_Buoni.buoni.AddAsync(model2);
|
||||
await _LW_Buoni.SaveChangesAsync();
|
||||
transaction.Commit();
|
||||
}
|
||||
*/
|
||||
|
||||
#endregion
|
||||
break;
|
||||
case Clienti.Syscom:
|
||||
|
||||
#region inserimento tabella
|
||||
BuoniLW modelsys = new BuoniLW();
|
||||
modelsys.azienda = ten;
|
||||
if (nomefile.Length > 8)
|
||||
nomefile = nomefile.Substring(0, 8);
|
||||
modelsys.ser_buono = nomefile;
|
||||
modelsys.dt_ins = DateTime.Now;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
files.CopyTo(ms);
|
||||
byte[] byteArray = ms.GetBuffer();
|
||||
string base64String = Convert.ToBase64String(byteArray);
|
||||
modelsys.immagine = base64String;
|
||||
}
|
||||
//scrittura
|
||||
/*
|
||||
using (var transaction = _Sys_Buoni.Database.BeginTransaction())
|
||||
{
|
||||
await _Sys_Buoni.buoni.AddAsync(modelsys);
|
||||
await _Sys_Buoni.SaveChangesAsync();
|
||||
transaction.Commit();
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format("*********** {2} FINE Chiamata al metodo upload: tenant:{0} tenant2: {3} tenantConf: {4} file: {1} tecnico:{5}", ten, nomefile, DateTime.Now.ToString(), ten2, tenConf, tecnico));
|
||||
return Ok(new { count = 1, size });
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -12052,8 +11994,6 @@ namespace ApiPolo.Controllers
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Logging
|
||||
/// <summary>Upload return:ActionResult</summary>
|
||||
[HttpPost]
|
||||
|
||||
@ -63,6 +63,8 @@ namespace ApiPolo.Data
|
||||
public DbSet<Compo_Impia>? Compo { get; set; }
|
||||
|
||||
public DbSet<ChiamateTable>? ChiamateTables { get; set; }
|
||||
|
||||
public DbSet<BuoniLW>? Buoni { get; set; }
|
||||
#endregion
|
||||
|
||||
public TenantDbContext(DbContextOptions<TenantDbContext> options, IConfiguration configuration, string tenant)
|
||||
@ -208,6 +210,18 @@ namespace ApiPolo.Data
|
||||
table.chserial
|
||||
});
|
||||
}, "CHIAMATE");
|
||||
|
||||
TryConfigureEntity(mb =>
|
||||
{
|
||||
mb.Entity<BuoniLW>().ToTable("BUONI");
|
||||
mb.Entity<BuoniLW>().HasKey(table => new
|
||||
{
|
||||
table.azienda,
|
||||
table.ser_buono
|
||||
});
|
||||
}, "BUONI");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,5 +175,27 @@ namespace ApiPolo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Scrive su BUONI: upload immagine buono in metodo chiudi</summary>
|
||||
public async Task AddBuonoToDbAsync(string tenant, BuoniLW model)
|
||||
{
|
||||
|
||||
var dbContext = _dbContextFactory.GetDbContext(tenant);
|
||||
|
||||
string mex = string.Empty;
|
||||
try
|
||||
{
|
||||
using (var transaction = await dbContext.Database.BeginTransactionAsync())
|
||||
{
|
||||
await dbContext.Buoni.AddAsync(model);
|
||||
await dbContext.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mex = ex.Message;
|
||||
throw new InvalidOperationException("Error in Service - AddRappNewToDbAsync: " + mex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user