diff --git a/ApiPolo/Controllers/PoloController.cs b/ApiPolo/Controllers/PoloController.cs index 1c01fb3..ca5d7ad 100644 --- a/ApiPolo/Controllers/PoloController.cs +++ b/ApiPolo/Controllers/PoloController.cs @@ -1384,7 +1384,11 @@ namespace ApiPolo.Controllers var dbContext = _dbContextFactory.GetDbContext(tenant); return dbContext.ChiamateTables; // Use Set() to handle different DbContexts } - + private DbSet getBuoniByTenant(string tenant) + { + var dbContext = _dbContextFactory.GetDbContext(tenant); + return dbContext.Buoni; // Use Set() 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 /// Upload return:ActionResult [HttpPost] diff --git a/ApiPolo/Data/TenantDbContext.cs b/ApiPolo/Data/TenantDbContext.cs index f3984ac..bfa50d2 100644 --- a/ApiPolo/Data/TenantDbContext.cs +++ b/ApiPolo/Data/TenantDbContext.cs @@ -63,6 +63,8 @@ namespace ApiPolo.Data public DbSet? Compo { get; set; } public DbSet? ChiamateTables { get; set; } + + public DbSet? Buoni { get; set; } #endregion public TenantDbContext(DbContextOptions options, IConfiguration configuration, string tenant) @@ -208,6 +210,18 @@ namespace ApiPolo.Data table.chserial }); }, "CHIAMATE"); + + TryConfigureEntity(mb => + { + mb.Entity().ToTable("BUONI"); + mb.Entity().HasKey(table => new + { + table.azienda, + table.ser_buono + }); + }, "BUONI"); + + } } } diff --git a/ApiPolo/Service.cs b/ApiPolo/Service.cs index bcafda1..26dbf4c 100644 --- a/ApiPolo/Service.cs +++ b/ApiPolo/Service.cs @@ -175,5 +175,27 @@ namespace ApiPolo } } + /// Scrive su BUONI: upload immagine buono in metodo chiudi + 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); + } + } } }