Michele: aggiunto model SedeConsegna + dbcontext + controller e metodi per ricerca committente e sede committente

This commit is contained in:
michele 2024-08-05 17:29:17 +02:00
parent c6afc2c9c4
commit 4bc8b1597f
4 changed files with 76 additions and 17 deletions

View File

@ -11,35 +11,48 @@ namespace ApiSoftway.Controllers
public class ClientiController : ControllerBase public class ClientiController : ControllerBase
{ {
private readonly GESA_CLIENTI_DbContext _dbClientiContext; private readonly GESA_CLIENTI_DbContext _dbClientiContext;
private readonly GESA_SEDECONSEGNA_DbContext _dbsedeconsegnaContext;
private DbSet<Clienti> _clienti; private DbSet<Clienti> _clienti;
private DbSet<SedeConsegna> _sedeconsegna;
private readonly ILogger<LoginController> _logger; private readonly ILogger<LoginController> _logger;
private readonly IConfiguration? _configuration; private readonly IConfiguration? _configuration;
public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, ILogger<LoginController> logger, IConfiguration? configuration) public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, GESA_SEDECONSEGNA_DbContext dbsedeconsegnaContext, ILogger<LoginController> logger, IConfiguration? configuration)
{ {
_dbClientiContext = dbClientiContext; _dbClientiContext = dbClientiContext;
_dbsedeconsegnaContext = dbsedeconsegnaContext;
_logger = logger; _logger = logger;
_configuration = configuration; _configuration = configuration;
} }
//[HttpGet("ListaClienti")] [HttpGet("GetCommittenti")]
//public async Task<ActionResult<IEnumerable<Clienti>>> GetClienti() public async Task<ActionResult<IEnumerable<Clienti>>> GetClienti()
//{ {
// List<Clienti> listClienti = new List<Clienti>(); List<Clienti> listClienti = new List<Clienti>();
// //Clienti cliente = new Clienti(); _clienti = _dbClientiContext.Cli;
// _clienti = _dbClientiContext.Cli; var lista = await _clienti.Where(x => x.Antipcon.Equals("C")).ToListAsync();
// var lista = await _clienti.ToListAsync();
// foreach (var client in lista) foreach (var client in lista)
// { {
// listClienti.Add(client); listClienti.Add(client);
// } }
// return listClienti; return listClienti;
}
//} [HttpGet("GetSediByCommittente")]
public async Task<ActionResult<IEnumerable<SedeConsegna>>> GetSediByCommittente(string codCom)
{
List<SedeConsegna> listSedi = new List<SedeConsegna>();
_sedeconsegna = _dbsedeconsegnaContext.SedeConsegna;
var listaSedi = await _sedeconsegna.Where(x => x.Pccodcon.Contains(codCom)).ToListAsync();
foreach (var sede in listaSedi)
{
listSedi.Add(sede);
}
return listSedi;
}
} }
} }

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
namespace ApiSoftway.Models.Gesa_DbContext
{
public class GESA_SEDECONSEGNA_DbContext : DbContext
{
public DbSet<SedeConsegna>? SedeConsegna { get; set; }
public GESA_SEDECONSEGNA_DbContext(DbContextOptions<GESA_SEDECONSEGNA_DbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SedeConsegna>().ToTable("GESAPIANICON");
modelBuilder.Entity<SedeConsegna>().HasKey(table => new
{
table.Pctipcon,
table.Pccodcon,
table.Cprownum
});
}
}
}

19
Models/SedeConsegna.cs Normal file
View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace ApiSoftway.Models
{
public class SedeConsegna
{
[Key]
public string? Pctipcon { get; set; }
[Key]
public string? Pccodcon { get; set; }
[Key]
public int? Cprownum { get; set; }
public int? Cproword { get; set; }
public string? Pccodsed { get; set; }
public string? Pcdescri { get; set; }
public string? Pcindiri { get; set; }
}
}

View File

@ -51,6 +51,9 @@ builder.Services.AddDbContext<GESA_AUTOMEZZI_DbContext>(options => options.UseSq
builder.Services.AddDbContext<GESA_CONSEGNE_M_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") builder.Services.AddDbContext<GESA_CONSEGNE_M_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
, options => { options.CommandTimeout(commandTimeoutInSeconds); } , options => { options.CommandTimeout(commandTimeoutInSeconds); }
)); ));
builder.Services.AddDbContext<GESA_SEDECONSEGNA_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
));
#endregion #endregion
@ -74,5 +77,5 @@ app.UseAuthorization();
app.MapControllers(); app.MapControllers();
//app.Run(); app.Run();
app.Run("http://localhost:6000"); //app.Run("http://localhost:6000");