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."); } } } }